Dear List, I'm experimenting with views and array indexing. I have written two code blocks that I was expecting to produce the same result.
First try: >>> a = np.arange(10) >>> b = a[np.array([1,6,5])] >>> b += 1 >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) Alternative version: >>> a = np.arange(10) >>> a[np.array([1,6,5])] += 1 >>> a array([0, 2, 2, 3, 4, 6, 7, 7, 8, 9]) I understand what is happening in the first case. In fact, the documentation is quite clear on the subject: For all cases of index arrays, what is returned is a copy of the original data, not a view as one gets for slices. What about the second case? There, I'm not keeping a reference to the intermediate copy (b, in the first example). Still, I don't see why the update (to the copy) is propagating to the original array. Is there any implementation detail that I'm missing? Best, ab
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion