Skip to content

Commit 28559a3

Browse files
authored
Merge pull request #91 from QuantEcon/modify_pattern
np.ones * alpha -->> np.full(, alpha)
2 parents fd28089 + 41e7fba commit 28559a3

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

lectures/amss.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ x_grid = UCGrid((x_min, x_max, x_num))
779779
crra_pref = CRRAutility(β=β, σ=σ, γ=γ)
780780
781781
S = len(Π)
782-
bounds_v = np.vstack([np.hstack([np.ones(S) * -10., np.zeros(S)]),
783-
np.hstack([np.ones(S) - g, np.ones(S) * 10])]).T
782+
bounds_v = np.vstack([np.hstack([np.full(S, -10.), np.zeros(S)]),
783+
np.hstack([np.ones(S) - g, np.full(S, 10.)])]).T
784784
785785
amss_model = AMSS(crra_pref, β, Π, g, x_grid, bounds_v)
786786
```
@@ -906,7 +906,7 @@ state-contingent debt (circles) and the economy with only a risk-free bond
906906
```{code-cell} python3
907907
# WARNING: DO NOT EXPECT THE CODE TO WORK IF YOU CHANGE PARAMETERS
908908
ψ = 0.69
909-
Π = 0.5 * np.ones((2, 2))
909+
Π = np.full((2, 2), 0.5)
910910
β = 0.9
911911
g = np.array([0.1, 0.2])
912912
@@ -923,11 +923,11 @@ bounds_v = np.vstack([np.zeros(2 * S), np.hstack([1 - g, np.ones(S)]) ]).T
923923
V = np.zeros((len(Π), x_num))
924924
V[:] = -(nodes(x_grid).T + x_max) ** 2 / 14
925925
926-
σ_v_star = 1 - np.ones((S, x_num, S * 2)) * 0.55
926+
σ_v_star = 1 - np.full((S, x_num, S * 2), 0.55)
927927
928928
W = np.empty(len(Π))
929929
b_0 = 0.5
930-
σ_w_star = 1 - np.ones((S, 2)) * 0.55
930+
σ_w_star = 1 - np.full((S, 2), 0.55)
931931
932932
amss_model = AMSS(log_pref, β, Π, g, x_grid, bounds_v)
933933
```

lectures/amss3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Here is a graph of a long simulation of 102000 periods.
179179
:tags: ["scroll-output"]
180180
μ_grid = np.linspace(-0.09, 0.1, 100)
181181
182-
log_example = CRRAutility(π=(1 / 3) * np.ones((3, 3)),
182+
log_example = CRRAutility(π=np.full((3, 3), 1 / 3),
183183
G=np.array([0.1, 0.2, .3]),
184184
Θ=np.ones(3))
185185
@@ -539,7 +539,7 @@ Now let's move on to compute things step by step.
539539
#### Step 1
540540
541541
```{code-cell} python3
542-
u = CRRAutility(π=(1 / 3) * np.ones((3, 3)),
542+
u = CRRAutility(π=np.full((3, 3), 1 / 3),
543543
G=np.array([0.1, 0.2, .3]),
544544
Θ=np.ones(3))
545545

lectures/arellano.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def solve(model, tol=1e-8, maxiter=10_000):
480480
iBstar = np.zeros((ny, nB), int64)
481481
default_prob = np.zeros((ny, nB))
482482
default_states = np.zeros((ny, nB))
483-
q = np.ones((ny, nB)) * 0.95
483+
q = np.full((ny, nB), 0.95)
484484
Vd = np.zeros(ny)
485485
Vc, V, Vupd = np.zeros((ny, nB)), np.zeros((ny, nB)), np.zeros((ny, nB))
486486

lectures/calvo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ beginning, i.e., $\theta^A_{t+10} =\theta^R_t \ \ \forall t \geq 0$.
11681168
def abreu_plan(clq, T=1000, T_A=10, μ_bar=0.1, T_Plot=20):
11691169
11701170
# Append Ramsey μ series to stick μ series
1171-
clq.μ_A = np.append(np.ones(T_A) * μ_bar, clq.μ_series[:-T_A])
1171+
clq.μ_A = np.append(np.full(T_A, μ_bar), clq.μ_series[:-T_A])
11721172
11731173
# Calculate implied stick θ series
11741174
clq.θ_A = np.zeros(T)

lectures/rosen_schooling_model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ k = 4 # Number of periods of schooling required to become an engineer
188188
α_d = np.array([[0.1]])
189189
α_s = 1
190190
ε_1 = 1e-7
191-
λ_1 = np.ones((1, k)) * ε_1
191+
λ_1 = np.full((1, k), ε_1)
192192
# Use of ε_1 is trick to aquire detectability, see HS2013 p. 228 footnote 4
193193
l_λ = np.hstack((α_d, λ_1))
194194
π_h = np.array([[0]])
@@ -244,7 +244,7 @@ econ2 = DLE(info1, tech1, pref2)
244244
α_d = np.array([[0.1]])
245245
246246
k = 7
247-
λ_1 = np.ones((1, k)) * ε_1
247+
λ_1 = np.full((1, k), ε_1)
248248
l_λ = np.hstack((α_d, λ_1))
249249
d1 = np.vstack((δ_n, np.zeros((k - 1, 1))))
250250
d2 = np.hstack((d1, np.eye(k)))
@@ -256,7 +256,7 @@ Pref3 = Preferences(β, l_λ, π_h, δ_h, θ_h)
256256
econ3 = DLE(info1, tech1, Pref3)
257257
258258
k = 10
259-
λ_1 = np.ones((1, k)) * ε_1
259+
λ_1 = np.full((1, k), ε_1)
260260
l_λ = np.hstack((α_d, λ_1))
261261
d1 = np.vstack((δ_n, np.zeros((k - 1, 1))))
262262
d2 = np.hstack((d1, np.eye(k)))

lectures/smoothing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def complete_ss(β, b0, x0, A, C, S_y, T=12):
299299
300300
# Constant level of consumption
301301
cbar = (1 - β) * (S_y @ rm @ x0 - b0)
302-
c_hist = np.ones(T) * cbar
302+
c_hist = np.full(T, cbar)
303303
304304
# Debt
305305
x_hist, y_hist = lss.simulate(T)
@@ -743,7 +743,7 @@ def consumption_incomplete(cp, s_path):
743743
db = ((1 - β) * v - y) / β
744744
745745
for i, s in enumerate(s_path):
746-
c_path[i] = (1 - β) * (v - b_path[i] * np.ones((n, 1)))[s, 0]
746+
c_path[i] = (1 - β) * (v - np.full((n, 1), b_path[i]))[s, 0]
747747
b_path[i + 1] = b_path[i] + db[s, 0]
748748
749749
return c_path, b_path[:-1], y[s_path]
@@ -922,7 +922,7 @@ fig, ax = plt.subplots(1, 2, figsize=(14, 4))
922922
923923
ax[0].set_title('Consumption paths')
924924
ax[0].plot(np.arange(N_simul), c_path, label='incomplete market')
925-
ax[0].plot(np.arange(N_simul), c_bar * np.ones(N_simul),
925+
ax[0].plot(np.arange(N_simul), np.full(N_simul, c_bar),
926926
label='complete market')
927927
ax[0].plot(np.arange(N_simul), y_path, label='income', alpha=.6, ls='--')
928928
ax[0].legend()

lectures/smoothing_tax.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def consumption_incomplete(cp, s_path):
227227
db = ((1 - β) * v - y) / β
228228
229229
for i, s in enumerate(s_path):
230-
c_path[i] = (1 - β) * (v - b_path[i] * np.ones((n, 1)))[s, 0]
230+
c_path[i] = (1 - β) * (v - np.full((n, 1), b_path[i]))[s, 0]
231231
b_path[i + 1] = b_path[i] + db[s, 0]
232232
233233
return c_path, b_path[:-1], y[s_path]
@@ -255,7 +255,7 @@ fig, ax = plt.subplots(1, 2, figsize=(14, 4))
255255
256256
ax[0].set_title('Consumption paths')
257257
ax[0].plot(np.arange(N_simul), c_path, label='incomplete market')
258-
ax[0].plot(np.arange(N_simul), c_bar * np.ones(N_simul), label='complete market')
258+
ax[0].plot(np.arange(N_simul), np.full(N_simul, c_bar), label='complete market')
259259
ax[0].plot(np.arange(N_simul), y_path, label='income', alpha=.6, ls='--')
260260
ax[0].legend()
261261
ax[0].set_xlabel('Periods')
@@ -289,7 +289,7 @@ fig, ax = plt.subplots(1, 2, figsize=(14, 4))
289289
290290
ax[0].set_title('Tax collection paths')
291291
ax[0].plot(np.arange(N_simul), c_path, label='incomplete market')
292-
ax[0].plot(np.arange(N_simul), c_bar * np.ones(N_simul), label='complete market')
292+
ax[0].plot(np.arange(N_simul), np.full(N_simul, c_bar), label='complete market')
293293
ax[0].plot(np.arange(N_simul), y_path, label='govt expenditures', alpha=.6, ls='--')
294294
ax[0].legend()
295295
ax[0].set_xlabel('Periods')
@@ -584,7 +584,7 @@ class TaxSmoothingExample:
584584
plt.figure()
585585
plt.title('Tax collection paths')
586586
plt.plot(np.arange(N), self.T_path, label='incomplete market')
587-
plt.plot(np.arange(N), self.T_bar * np.ones(N), label='complete market')
587+
plt.plot(np.arange(N), np.full(N, self.T_bar), label='complete market')
588588
plt.plot(np.arange(N), self.g_path, label='govt expenditures', alpha=.6, ls='--')
589589
plt.legend()
590590
plt.xlabel('Periods')

0 commit comments

Comments
 (0)