I have two arrays with the same length (6, in this example). One stores floats:
a = np.array([0.2, 0.01, 0.5, 0.7, 0., 0.002])
the second one stores indices (hence, int values):
indices = np.array([4, 9, 0, 2, 2, 4])
In my code I initialize another array, which has length in general different from that of a and indices, for example 10 in this example:
c = np.zeros(10)
I would like to find a Pythonic way to accomplish the following:
for i in range(len(indices)):
c[indices[i]] += a[i]
which, in this example, produces:
[0.5 0. 0.7 0. 0.202 0. 0. 0. 0. 0.01 ]
I tried looking at this brilliant example, however I am not sure how this can be applied here.