diff --git a/lectures/career.md b/lectures/career.md index a4c0f5e63..8f682b837 100644 --- a/lectures/career.md +++ b/lectures/career.md @@ -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 @@ -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. - diff --git a/lectures/geom_series.md b/lectures/geom_series.md index a3b0fa2d7..010c251e4 100644 --- a/lectures/geom_series.md +++ b/lectures/geom_series.md @@ -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') diff --git a/lectures/inventory_dynamics.md b/lectures/inventory_dynamics.md index 8c41b8037..ee3fbb087 100644 --- a/lectures/inventory_dynamics.md +++ b/lectures/inventory_dynamics.md @@ -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: diff --git a/lectures/lqcontrol.md b/lectures/lqcontrol.md index 680c9ab7e..32a7a6b39 100644 --- a/lectures/lqcontrol.md +++ b/lectures/lqcontrol.md @@ -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 diff --git a/lectures/markov_asset.md b/lectures/markov_asset.md index 964986bb6..5bccdb807 100644 --- a/lectures/markov_asset.md +++ b/lectures/markov_asset.md @@ -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]) @@ -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) diff --git a/lectures/mccall_correlated.md b/lectures/mccall_correlated.md index 03dad73a3..94b0e37a4 100644 --- a/lectures/mccall_correlated.md +++ b/lectures/mccall_correlated.md @@ -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 diff --git a/lectures/multi_hyper.md b/lectures/multi_hyper.md index 07d32e386..3bcba704a 100644 --- a/lectures/multi_hyper.md +++ b/lectures/multi_hyper.md @@ -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): diff --git a/lectures/odu.md b/lectures/odu.md index 650a3da08..5cefe5958 100644 --- a/lectures/odu.md +++ b/lectures/odu.md @@ -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 diff --git a/lectures/short_path.md b/lectures/short_path.md index 726c7fcb9..07cfba503 100644 --- a/lectures/short_path.md +++ b/lectures/short_path.md @@ -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) diff --git a/lectures/time_series_with_matrices.md b/lectures/time_series_with_matrices.md index d34c47d01..4ba4638cc 100644 --- a/lectures/time_series_with_matrices.md +++ b/lectures/time_series_with_matrices.md @@ -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 ``` @@ -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 ``` diff --git a/lectures/wealth_dynamics.md b/lectures/wealth_dynamics.md index c2a50ece7..2d8cde333 100644 --- a/lectures/wealth_dynamics.md +++ b/lectures/wealth_dynamics.md @@ -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) @@ -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 ``` @@ -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)