Assuming I have a numpy array like: [1,2,3,4,5,6] and another array: [0,0,1,2,2,1] I want to sum the items in the first array by group (the second array) and obtain n-groups
You're all wrong! The best way to do it is:
a = [1,2,3,4,5,6] ix = [0,0,1,2,2,1] accum = np.zeros(np.max(ix)+1) np.add.at(accum, ix, a) print accum > array([ 3., 9., 9.])