Anakim Border
2016-08-08 13:11:17 UTC
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.
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
I'm experimenting with views and array indexing. I have written two code
blocks that I was expecting to produce the same result.
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])b = a[np.array([1,6,5])]
b += 1
a
a = np.arange(10)
a[np.array([1,6,5])] += 1
a
array([0, 2, 2, 3, 4, 6, 7, 7, 8, 9])a[np.array([1,6,5])] += 1
a
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