I have two numpy arrays:
a = np.arange(100*100).reshape(100,100)
b = np.random.rand(100, 100)
I also have a tuple of slices to extract a ce
Slicing a numpy array returns a view, but boolean indexing returns a copy of an array. So when you indexed it first time with boolean index in a[slice_][indices][high_indices]
, you got back a copy, and the value 42 is assigned to a copy and not to the array a
. You can solve the problem by chaining the boolean index:
a[slice_][(a[slice_] > 700) & (b[slice_] > 0.5)] = 42