I had a weird behaviour trying to change the value of an element of a numpy array today, and I would like to understand why it didn't work. I have two arrays (a and b), and I want to change the values of b where a > 0.
a = array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
b = array([[ 5., 0., 0.],
[ 0., 5., 0.],
[ 0., 0., 5.]])
mask = a > 0
print b[mask][0]
=> 5.0
b[mask][0] = 10
print b[mask][0]
=> 5.0
Could someone please explain why the assignment b[mask][0] didn't change my value 5.0?