I\'m looking for a fast solution to MATLAB\'s accumarray in numpy. The accumarray accumulates the elements of an array which belong to the same index. An exampl
accumarray
Not as good as the accepted answer but:
[np.sum([a[x] for x in y]) for y in [list(np.where(accmap==z)) for z in np.unique(accmap).tolist()]]
This takes 108us per loop (100000 loops, best of 3)
108us per loop
The accepted answer (np.bincount(accmap, weights=a) takes 2.05us per loop (100000 loops, best of 3)
np.bincount(accmap, weights=a
2.05us per loop