1

The numpy docs specifically mention the following "gotcha":

This particular example is often surprising to people:

>>> x = np.arange(0, 50, 10)
>>> x
array([ 0, 10, 20, 30, 40])
>>> x[np.array([1, 1, 3, 1])] += 1
>>> x
array([ 0, 11, 20, 31, 40])

Where people expect that the 1st location will be incremented by 3. In fact, it will only be incremented by 1. The reason is because...

However, they do not specify how to achieve the behavior that "people expect". Specifically, I would like to have the behavior where x becomes array([0, 13, 20, 31, 40]) (i.e. the 1st location is incremented by 3).

Is there a nice way to increment an array indexed array in this fashion?

0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.