How does python work for the object operation?
Solution 1:
c = c-1
creates a new array from c-1
and assigns that to c
. It doesn't modify the original array.
c[c==4] = c[c==4]-1
is assigning to the selected elements of c
, which modifies the array in place.
And since c
is a view into a
, it also modifies a
at the same time.