Skip to content

Commit 6e7ff58

Browse files
authored
Merge pull request #168 from QuantEcon/modify_patterns
change ``np.ones`` patterns to ``np.full``
2 parents be8c7fc + f01ccd2 commit 6e7ff58

11 files changed

+15
-17
lines changed

lectures/career.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def solve_model(cw,
288288
T, _ = operator_factory(cw, parallel_flag=use_parallel)
289289
290290
# Set up loop
291-
v = np.ones((cw.grid_size, cw.grid_size)) * 100 # Initial guess
291+
v = np.full((cw.grid_size, cw.grid_size), 100.) # Initial guess
292292
i = 0
293293
error = tol + 1
294294
@@ -519,4 +519,3 @@ In the new figure, you see that the region for which the worker
519519
stays put has grown because the distribution for $\epsilon$
520520
has become more concentrated around the mean, making high-paying jobs
521521
less realistic.
522-

lectures/geom_series.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ T = np.arange(0, T_max+1)
720720
fig, ax = plt.subplots()
721721
ax.set_title('Infinite and Finite Lease Present Value $T$ Periods Ahead')
722722
f_1 = finite_lease_pv_true(T, g, r, x_0)
723-
f_2 = np.ones(T_max+1)*infinite_lease(g, r, x_0)
723+
f_2 = np.full(T_max+1, infinite_lease(g, r, x_0))
724724
ax.plot(T, f_1, label='T-period lease PV')
725725
ax.plot(T, f_2, '--', label='Infinite lease PV')
726726
ax.set_xlabel('$T$ Periods Ahead')

lectures/inventory_dynamics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ first_diffs = np.diff(sample_dates)
352352
353353
fig, ax = plt.subplots()
354354
355-
X = np.ones(num_firms) * x_init
355+
X = np.full(num_firms, x_init)
356356
357357
current_date = 0
358358
for d in first_diffs:

lectures/lqcontrol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ c = up.flatten() + c_bar # Consumption
14701470
14711471
time = np.arange(1, K+1)
14721472
income_w = σ * wp_w[0, 1:K+1] + m1 * time + m2 * time**2 # Income
1473-
income_r = np.ones(T-K) * s
1473+
income_r = np.full(T-K, s)
14741474
income = np.concatenate((income_w, income_r))
14751475
14761476
# Plot results

lectures/markov_asset.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ Consider the following primitives
922922

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

10111011
```{code-cell} python3
10121012
n = 5
1013-
P = 0.0125 * np.ones((n, n))
1013+
P = np.full((n, n), 0.0125)
10141014
P += np.diag(0.95 - 0.0125 * np.ones(5))
10151015
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05]) # State values
10161016
mc = qe.MarkovChain(P, state_values=s)

lectures/mccall_correlated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def compute_fixed_point(js,
265265
verbose=True,
266266
print_skip=25):
267267
268-
f_init = np.log(js.c) * np.ones(len(js.z_grid))
268+
f_init = np.full(len(js.z_grid), np.log(js.c))
269269
f_out = np.empty_like(f_init)
270270
271271
# Set up loop

lectures/multi_hyper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class Urn:
218218
μ = n * K_arr / N
219219
220220
# variance-covariance matrix
221-
Σ = np.ones((c, c)) * n * (N - n) / (N - 1) / N ** 2
221+
Σ = np.full((c, c), n * (N - n) / (N - 1) / N ** 2)
222222
for i in range(c-1):
223223
Σ[i, i] *= K_arr[i] * (N - K_arr[i])
224224
for j in range(i+1, c):

lectures/odu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def simulate_path(F_a=F_a,
783783
"""Simulates path of employment for N number of works over T periods"""
784784
785785
e = np.ones((N, T+1))
786-
π = np.ones((N, T+1)) * 1e-3
786+
π = np.full((N, T+1), 1e-3)
787787
788788
a, b = G_a, G_b # Initial distribution parameters
789789

lectures/short_path.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ destination_node = 99
389389
def map_graph_to_distance_matrix(in_file):
390390
391391
# First let's set of the distance matrix Q with inf everywhere
392-
Q = np.ones((num_nodes, num_nodes))
393-
Q = Q * np.inf
392+
Q = np.full((num_nodes, num_nodes), np.inf)
394393
395394
# Now we read in the data and modify Q
396395
infile = open(in_file)

lectures/time_series_with_matrices.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ for i in range(T):
157157
if i-2 >= 0:
158158
A[i, i-2] = -𝛼2
159159
160-
b = np.ones(T) * 𝛼0
160+
b = np.full(T, 𝛼0)
161161
b[0] = 𝛼0 + 𝛼1 * y0 + 𝛼2 * y_1
162162
b[1] = 𝛼0 + 𝛼2 * y0
163163
```
@@ -200,7 +200,7 @@ then $y_{t}$ will be constant
200200
y_1_steady = 𝛼0 / (1 - 𝛼1 - 𝛼2) # y_{-1}
201201
y0_steady = 𝛼0 / (1 - 𝛼1 - 𝛼2)
202202
203-
b_steady = np.ones(T) * 𝛼0
203+
b_steady = np.full(T, 𝛼0)
204204
b_steady[0] = 𝛼0 + 𝛼1 * y0_steady + 𝛼2 * y_1_steady
205205
b_steady[1] = 𝛼0 + 𝛼2 * y0_steady
206206
```

lectures/wealth_dynamics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):
441441
Generate the Lorenz curve data and gini coefficient corresponding to a
442442
WealthDynamics mode by simulating num_households forward to time T.
443443
"""
444-
ψ_0 = np.ones(num_households) * wdy.y_mean
444+
ψ_0 = np.full(num_households, wdy.y_mean)
445445
z_0 = wdy.z_mean
446446
447447
ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)
@@ -576,7 +576,7 @@ For sample size and initial conditions, use
576576
```{code-cell} ipython3
577577
num_households = 250_000
578578
T = 500 # shift forward T periods
579-
ψ_0 = np.ones(num_households) * wdy.y_mean # initial distribution
579+
ψ_0 = np.full(num_households, wdy.y_mean) # initial distribution
580580
z_0 = wdy.z_mean
581581
```
582582

@@ -616,7 +616,7 @@ First let's generate the distribution:
616616
```{code-cell} ipython3
617617
num_households = 250_000
618618
T = 500 # how far to shift forward in time
619-
ψ_0 = np.ones(num_households) * wdy.y_mean
619+
ψ_0 = np.full(num_households, wdy.y_mean)
620620
z_0 = wdy.z_mean
621621
622622
ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)

0 commit comments

Comments
 (0)