I have an array:
A = np.array([0, 0, 0])
and list of indices with repetitions:
idx = [0, 0, 1, 1, 2, 2]
and another array i would like to add to A using indices above:
B = np.array([1, 1, 1, 1, 1, 1])
The operation:
A[idx] += B
Gives the result: array([1, 1, 1])
, so obviously values from B
were not summed up. What is the best way to get as a result array([2, 2, 2])
? Do I have to iterate over indices?