Why do we have two different behaviors on these np.array?
def pass_by_ref(A: np.array):
A = np.ones((2,2))
return A
def pass_by_ref_sideEffect(A: np.array):
A[0][0] = 2
return A
A = np.zeros((2,2))
B = pass_by_ref(A)
print("A =\n", A)
print("B =\n", B)
C = pass_by_ref_sideEffect(A)
print("A =\n", A)
print("C =\n", C)
output:
A =
[[0. 0.]
[0. 0.]]
B =
[[1. 1.]
[1. 1.]]
A =
[[2. 0.]
[0. 0.]]
C =
[[2. 0.]
[0. 0.]]
Why we have side effect on A after pass_by_ref_sideEffect and not with pass_by_ref?