I'm very puzzled by the following behaviour of NumPy when assigning elements to an array using an array as indices. Here is a minimal working example:
import numpy as np
i = np.arange(2,4)
a = np.arange(5)
a[:][i] = 0 # this modifies the a array
print(a)
b = np.arange(5)
b[i][:] = 0 # this does NOT modify the b array
print(b)
Why is the a array modified and not the b array? I suspect we are modifying a copy of the b array, but I'm not sure how to show this explicitly. For example, id(a) and id(a[:]) yield different results, yet a is modified.