0

Consider I have an array:

arr2 = np.array([10., 10., 10.,  10.,  10.,  10., 10., 10., 10., 10.])

and an index with repeated values:

idx = np.array([3,3,3,4,4,5])

If I do so:

arr2[idx] -=1

then I got this:

array([10., 10., 10.,  9.,  9.,  9., 10., 10., 10., 10.])

But I want to subtract by each value in index, taking into account the repetitions! How to get this?

array([10., 10., 10.,  7.,  8.,  9., 10., 10., 10., 10.])
3
  • 1
    for i in idx: arr2[i] -= 1 Commented Jun 3, 2020 at 13:59
  • 2
    np.add.at handkes the duplicates as you want Commented Jun 3, 2020 at 14:06
  • @hpaulj Thanx, that it! Commented Jun 3, 2020 at 14:11

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.