Skip to content

Commit 511f044

Browse files
committed
use numpy
1 parent 3473bcb commit 511f044

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lectures/mle.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ We'll require the following imports:
4646

4747

4848
```{code-cell} ipython3
49+
import numpy as np
4950
import jax.numpy as jnp
5051
import jax
5152
import pandas as pd
@@ -639,16 +640,16 @@ likelihood estimates.
639640
Before we begin, let's re-estimate our simple model with `statsmodels`
640641
to confirm we obtain the same coefficients and log-likelihood value.
641642

642-
Now, as `statsmodels` accepts only NumPy arrays, we can use the `__array__` method
643-
of JAX arrays to convert them to NumPy arrays.
643+
Now, as `statsmodels` accepts only NumPy arrays, we can use `np.array` method
644+
to convert them to NumPy arrays.
644645

645646
```{code-cell} ipython3
646647
X = jnp.array([[1, 2, 5], [1, 1, 3], [1, 4, 2], [1, 5, 2], [1, 3, 1]])
647648
648649
y = jnp.array([1, 0, 1, 1, 0])
649650
650-
y_numpy = y.__array__()
651-
X_numpy = X.__array__()
651+
y_numpy = np.array(y)
652+
X_numpy = np.array(X)
652653
stats_poisson = Poisson(y_numpy, X_numpy).fit()
653654
print(stats_poisson.summary())
654655
```
@@ -993,9 +994,8 @@ newton_raphson(prob, β)
993994

994995
```{code-cell} ipython3
995996
# Use statsmodels to verify results
996-
# Note: use __array__() method to convert jax to numpy arrays
997-
y_numpy = y.__array__()
998-
X_numpy = X.__array__()
997+
y_numpy = np.array(y)
998+
X_numpy = np.array(X)
999999
print(Probit(y_numpy, X_numpy).fit().summary())
10001000
```
10011001

0 commit comments

Comments
 (0)