Numpy sum elements in array based on its value

np.add.at(d, i, v)

You’d think d[i] += v would work, but if you try to do multiple additions to the same cell that way, one of them overrides the others. The ufunc.at method avoids those problems.

Leave a Comment