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.])
for i in idx: arr2[i] -= 1np.add.athandkes the duplicates as you want