To the following array
my_array = np.array([[11,12],[21,22],[31,32]])
I want to add 100 to the even values, so I write:
my_array[my_array % 2==0]+=100
print(my_array)
[[ 11 112]
[ 21 122]
[ 31 132]]
which is fine. Now if I write it with the plus symbol on the other side I get:
my_array[my_array % 2==0]=+100
print(my_array)
[[ 11 100]
[ 21 100]
[ 31 100]]
It seems to replace instead of adding the value, or to add the value to the result of the filter. Could somebody explain to me the reasons behind this and if this is the expected behaviour? Thanks !!!
+100i.e.100to those masked places. What exactly is the confusion again?a+=b is same as a = a+b.a =+ b is nothing but a = (+b)