In Python >= 3.5:
x = np.zeros((2,3))
for x_e in x:
x_e += 123
This operation returns a 2x3
matrix of all 123
's. Whereas the following returns all zeros:
x = np.zeros((2,3))
for x_e in x:
x_e = 123
This is a little off putting to me since x_e
is an element from x
and it doesn't totally feel like x
is being updated.
Okay, I think this is a thing, and it is called 'in place' update? (similar to an in place algorithm?)
But, the jarring thing is this does not work with lists:
x = [0,0,0]
for x_e in x:
x_e += 123
This returns the list
[0, 0, 0]
I would appreciate if someone can enlighten me on what precisely is happening here.