So with numpy arrays assigning one to another just copies the reference: i.e.
import numpy as np
x = np.array([5,8])
y = x
y += 1
x
Out: array([6, 9])
And if I want a deep copy then I should use x.copy(). And the same is true when taking a view out of a higher dimensional array, e.g.
A=np.array([[4,10],[8,1]])
b=A[:,1]
b+=1
A
Out: array([[ 4, 11],
[ 8, 2]])
And the other way round (continuing from above):
A[:,1]=b
b
Out: array([11, 2])
b+=1
A
Out: array([[ 4, 12],
[ 8, 3]])
So up to here everything is working consistently. But now if I carry on and do:
A[:,0] = b
A
Out: array([[12, 12],
[ 3, 3]])
b
Out: array([12, 3])
b+=1
A
Out: array([[12, 13],
[ 3, 4]])
What I don't understand is why the first column stays the same and the other doesn't? Why does the second column continue to point to the b array? Is there any rule for deciding when an array will be deep copied on assignment?