Python
numpy

numpy bincount and weights attribute

w = np.array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights
x = np.array([0, 1, 1, 2, 2, 2])
print(np.bincount(x,  weights=w))
X = [1,2,3,4,5,6]
I = [1,3,9,3,4,1]
F = np.bincount(I,X)
print(F)
print(np.bincount(X,I))
[ 0.3  0.7  1.1]
[ 0.  7.  0.  6.  5.  0.  0.  0.  0.  3.]
[ 0.  1.  3.  9.  3.  4.  1.]

Refs.