On Mon, Aug 8, 2016 at 6:11 AM, Anakim Border wrote:
> 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 haven't checked, but a likely explanation is that Python itself
interprets a[b] += c as a[b] = a[b] + c.
Pyth
Hi Anakim,
The difference is really in the code path that gets taken: in the first
case, you go through `a.__getitem__(np.array([1,6,5])`, in the second
through `a.__setitem__(...)`. The increments would not work if you added an
extra indexing to it, as in:
```
a[np.array([1,6,5])][:] += 1
```
(
On Mo, 2016-08-08 at 15:11 +0200, Anakim Border wrote:
> 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