Skip to content

Commit 2abf38b

Browse files
authored
Merge pull request #170 from QuantEcon/pattern_change
np.ones * alpha -->> np.full
2 parents 6e7ff58 + afc4eec commit 2abf38b

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

lectures/complex_and_trig.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ $z = 1 + \sqrt{3} i$.
120120
```{code-cell} python3
121121
# Abbreviate useful values and functions
122122
π = np.pi
123-
zeros = np.zeros
124-
ones = np.ones
123+
125124
126125
# Set parameters
127126
r = 2
@@ -135,9 +134,9 @@ fig = plt.figure(figsize=(8, 8))
135134
ax = plt.subplot(111, projection='polar')
136135
137136
ax.plot((0, θ), (0, r), marker='o', color='b') # Plot r
138-
ax.plot(zeros(x_range.shape), x_range, color='b') # Plot x
137+
ax.plot(np.zeros(x_range.shape), x_range, color='b') # Plot x
139138
ax.plot(θ_range, x / np.cos(θ_range), color='b') # Plot y
140-
ax.plot(θ_range, ones(θ_range.shape) * 0.1, color='r') # Plot θ
139+
ax.plot(θ_range, np.full(θ_range.shape, 0.1), color='r') # Plot θ
141140
142141
ax.margins(0) # Let the plot starts at origin
143142

lectures/inventory_dynamics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ legend_args = {'ncol': 3,
140140
'mode': 'expand'}
141141
142142
ax.plot(X, label="inventory")
143-
ax.plot(s * np.ones(sim_length), 'k--', label="$s$")
144-
ax.plot(S * np.ones(sim_length), 'k-', label="$S$")
143+
ax.plot(np.full(sim_length, s), 'k--', label="$s$")
144+
ax.plot(np.full(sim_length, S), 'k-', label="$S$")
145145
ax.set_ylim(0, S+10)
146146
ax.set_xlabel("time")
147147
ax.legend(**legend_args)
@@ -156,8 +156,8 @@ the probabilities of different outcomes:
156156
sim_length=200
157157
fig, ax = plt.subplots()
158158
159-
ax.plot(s * np.ones(sim_length), 'k--', label="$s$")
160-
ax.plot(S * np.ones(sim_length), 'k-', label="$S$")
159+
ax.plot(np.full(sim_length, s), 'k--', label="$s$")
160+
ax.plot(np.full(sim_length, S), 'k-', label="$S$")
161161
ax.set_ylim(0, S+10)
162162
ax.legend(**legend_args)
163163

lectures/lake_model.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class LakeModel:
265265
--------
266266
xbar : steady state vector of employment and unemployment rates
267267
"""
268-
x = 0.5 * np.ones(2)
268+
x = np.full(2, 0.5)
269269
error = tol + 1
270270
while error > tol:
271271
new_x = self.A_hat @ x
@@ -1049,7 +1049,7 @@ class LakeModelModified:
10491049
--------
10501050
xbar : steady state vector of employment and unemployment rates
10511051
"""
1052-
x = 0.5 * np.ones(2)
1052+
x = np.full(2, 0.5)
10531053
error = tol + 1
10541054
while error > tol:
10551055
new_x = self.A_hat @ x

lectures/markov_asset.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ Consider the following primitives
923923
```{code-cell} python3
924924
n = 5
925925
P = np.full((n, n), 0.0125)
926-
P += np.diag(0.95 - 0.0125 * np.ones(5))
926+
P[range(n), range(n)] += 1 - P.sum(1)
927927
# State values of the Markov chain
928928
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05])
929929
γ = 2.0
@@ -1011,7 +1011,7 @@ First, let's enter the parameters:
10111011
```{code-cell} python3
10121012
n = 5
10131013
P = np.full((n, n), 0.0125)
1014-
P += np.diag(0.95 - 0.0125 * np.ones(5))
1014+
P[range(n), range(n)] += 1 - P.sum(1)
10151015
s = np.array([0.95, 0.975, 1.0, 1.025, 1.05]) # State values
10161016
mc = qe.MarkovChain(P, state_values=s)
10171017

lectures/multivariate_normal.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ test scores $\sigma_{y}$.
514514
```{code-cell} python3
515515
def construct_moments_IQ(n, μθ, σθ, σy):
516516
517-
μ_IQ = np.ones(n+1) * μθ
517+
μ_IQ = np.full(n+1, μθ)
518518
519519
D_IQ = np.zeros((n+1, n+1))
520520
D_IQ[range(n), range(n)] = σy
@@ -1710,7 +1710,7 @@ A_inv = np.linalg.inv(A)
17101710

17111711
```{code-cell} python3
17121712
# compute the mean vectors of b and y
1713-
μb = np.ones(T) * 𝛼0
1713+
μb = np.full(T, 𝛼0)
17141714
μb[0] += 𝛼1 * μy_tilde[1] + 𝛼2 * μy_tilde[0]
17151715
μb[1] += 𝛼2 * μy_tilde[1]
17161716

lectures/samuelson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def param_plot():
431431
# Draw (t1, t2) points
432432
ρ1 = np.linspace(-2, 2, 100)
433433
ax.plot(ρ1, -abs(ρ1) + 1, c='black')
434-
ax.plot(ρ1, np.ones_like(ρ1) * -1, c='black')
434+
ax.plot(ρ1, np.full_like(ρ1, -1), c='black')
435435
ax.plot(ρ1, -(ρ1**2 / 4), c='black')
436436
437437
# Turn normal axes off

0 commit comments

Comments
 (0)