Code:
import numpy as np
def f(a):
return np.array([0, 1])
N_x, N_y = 4, 3
U = V = np.zeros((N_x, N_y))
for n_y in range(N_y):
for n_x in range(N_x):
U[n_x, n_y], V[n_x, n_y] = f(0)
print(U, V)
This gives the unexpected output:
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]] [[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
But if I use
U = np.zeros((N_x, N_y))
V = np.zeros((N_x, N_y))
instead of U = V = np.zeros((N_x, N_y))
, I get the following expected result.
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]] [[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
Question: What has gone awry here?