Skip to content

change np.ones patterns to np.full #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lectures/career.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def solve_model(cw,
T, _ = operator_factory(cw, parallel_flag=use_parallel)

# Set up loop
v = np.ones((cw.grid_size, cw.grid_size)) * 100 # Initial guess
v = np.full((cw.grid_size, cw.grid_size), 100.) # Initial guess
i = 0
error = tol + 1

Expand Down Expand Up @@ -519,4 +519,3 @@ In the new figure, you see that the region for which the worker
stays put has grown because the distribution for $\epsilon$
has become more concentrated around the mean, making high-paying jobs
less realistic.

2 changes: 1 addition & 1 deletion lectures/geom_series.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ T = np.arange(0, T_max+1)
fig, ax = plt.subplots()
ax.set_title('Infinite and Finite Lease Present Value $T$ Periods Ahead')
f_1 = finite_lease_pv_true(T, g, r, x_0)
f_2 = np.ones(T_max+1)*infinite_lease(g, r, x_0)
f_2 = np.full(T_max+1, infinite_lease(g, r, x_0))
ax.plot(T, f_1, label='T-period lease PV')
ax.plot(T, f_2, '--', label='Infinite lease PV')
ax.set_xlabel('$T$ Periods Ahead')
Expand Down
2 changes: 1 addition & 1 deletion lectures/inventory_dynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ first_diffs = np.diff(sample_dates)

fig, ax = plt.subplots()

X = np.ones(num_firms) * x_init
X = np.full(num_firms, x_init)

current_date = 0
for d in first_diffs:
Expand Down
2 changes: 1 addition & 1 deletion lectures/lqcontrol.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ c = up.flatten() + c_bar # Consumption

time = np.arange(1, K+1)
income_w = σ * wp_w[0, 1:K+1] + m1 * time + m2 * time**2 # Income
income_r = np.ones(T-K) * s
income_r = np.full(T-K, s)
income = np.concatenate((income_w, income_r))

# Plot results
Expand Down
4 changes: 2 additions & 2 deletions lectures/markov_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ Consider the following primitives

```{code-cell} python3
n = 5
P = 0.0125 * np.ones((n, n))
P = np.full((n, n), 0.0125)
P += np.diag(0.95 - 0.0125 * np.ones(5))
# State values of the Markov chain
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05])
Expand Down Expand Up @@ -1010,7 +1010,7 @@ First, let's enter the parameters:

```{code-cell} python3
n = 5
P = 0.0125 * np.ones((n, n))
P = np.full((n, n), 0.0125)
P += np.diag(0.95 - 0.0125 * np.ones(5))
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05]) # State values
mc = qe.MarkovChain(P, state_values=s)
Expand Down
2 changes: 1 addition & 1 deletion lectures/mccall_correlated.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def compute_fixed_point(js,
verbose=True,
print_skip=25):

f_init = np.log(js.c) * np.ones(len(js.z_grid))
f_init = np.full(len(js.z_grid), np.log(js.c))
f_out = np.empty_like(f_init)

# Set up loop
Expand Down
2 changes: 1 addition & 1 deletion lectures/multi_hyper.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Urn:
μ = n * K_arr / N

# variance-covariance matrix
Σ = np.ones((c, c)) * n * (N - n) / (N - 1) / N ** 2
Σ = np.full((c, c), n * (N - n) / (N - 1) / N ** 2)
for i in range(c-1):
Σ[i, i] *= K_arr[i] * (N - K_arr[i])
for j in range(i+1, c):
Expand Down
2 changes: 1 addition & 1 deletion lectures/odu.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def simulate_path(F_a=F_a,
"""Simulates path of employment for N number of works over T periods"""

e = np.ones((N, T+1))
π = np.ones((N, T+1)) * 1e-3
π = np.full((N, T+1), 1e-3)

a, b = G_a, G_b # Initial distribution parameters

Expand Down
3 changes: 1 addition & 2 deletions lectures/short_path.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ destination_node = 99
def map_graph_to_distance_matrix(in_file):

# First let's set of the distance matrix Q with inf everywhere
Q = np.ones((num_nodes, num_nodes))
Q = Q * np.inf
Q = np.full((num_nodes, num_nodes), np.inf)

# Now we read in the data and modify Q
infile = open(in_file)
Expand Down
4 changes: 2 additions & 2 deletions lectures/time_series_with_matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ for i in range(T):
if i-2 >= 0:
A[i, i-2] = -𝛼2

b = np.ones(T) * 𝛼0
b = np.full(T, 𝛼0)
b[0] = 𝛼0 + 𝛼1 * y0 + 𝛼2 * y_1
b[1] = 𝛼0 + 𝛼2 * y0
```
Expand Down Expand Up @@ -200,7 +200,7 @@ then $y_{t}$ will be constant
y_1_steady = 𝛼0 / (1 - 𝛼1 - 𝛼2) # y_{-1}
y0_steady = 𝛼0 / (1 - 𝛼1 - 𝛼2)

b_steady = np.ones(T) * 𝛼0
b_steady = np.full(T, 𝛼0)
b_steady[0] = 𝛼0 + 𝛼1 * y0_steady + 𝛼2 * y_1_steady
b_steady[1] = 𝛼0 + 𝛼2 * y0_steady
```
Expand Down
6 changes: 3 additions & 3 deletions lectures/wealth_dynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):
Generate the Lorenz curve data and gini coefficient corresponding to a
WealthDynamics mode by simulating num_households forward to time T.
"""
ψ_0 = np.ones(num_households) * wdy.y_mean
ψ_0 = np.full(num_households, wdy.y_mean)
z_0 = wdy.z_mean

ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)
Expand Down Expand Up @@ -576,7 +576,7 @@ For sample size and initial conditions, use
```{code-cell} ipython3
num_households = 250_000
T = 500 # shift forward T periods
ψ_0 = np.ones(num_households) * wdy.y_mean # initial distribution
ψ_0 = np.full(num_households, wdy.y_mean) # initial distribution
z_0 = wdy.z_mean
```

Expand Down Expand Up @@ -616,7 +616,7 @@ First let's generate the distribution:
```{code-cell} ipython3
num_households = 250_000
T = 500 # how far to shift forward in time
ψ_0 = np.ones(num_households) * wdy.y_mean
ψ_0 = np.full(num_households, wdy.y_mean)
z_0 = wdy.z_mean

ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)
Expand Down