This is my code
import numpy as np
v = np.zeros(4)
backup = np.zeros(4)
for i in range(3):
backup = v
v[0] = 1
print(backup)
My output is:
[1. 0. 0. 0.]
[1. 0. 0. 0.]
[1. 0. 0. 0.]
But I expected:
[0. 0. 0. 0.]
[1. 0. 0. 0.]
[1. 0. 0. 0.]
Why does backup matrix get updated before assignment?