If you change a view of a numpy array, the original array is also altered. This is intended behaviour.
arr = np.array([1,2,3])
mask = np.array([True, False, False])
arr[mask] = 0
arr
# Out: array([0, 2, 3])
However, if I take a view of such a view, and change that, then the original array is not altered:
arr = np.array([1,2,3])
mask_1 = np.array([True, False, False])
mask_1_arr = arr[mask_1] # Becomes: array([1])
mask_2 = np.array([True])
mask_1_arr[mask_2] = 0
arr
# Out: array([1, 2, 3])
This implies to me that, when you take a view of a view, you actually get back a copy. Is this correct? Why is this?
The same behaviour occurs if I use numpy arrays of numerical indices instead of a numpy array of boolean values. (E.g. arr[np.array([0])][np.array([0])] = 0 doesn't change the first element of arr to 0.)