I am new to Python and Numpy, but it looks like you can use the .at ufunc method rather than reduceat :
import numpy as np data_id = np.array([0,0,0,1,1,1,1,2,2,2,3,3,3,4,5,5,5]) data_val = np.random.rand(len(data_id)) ans = np.empty(data_id[-1]+1)
For instance:
data_val = array([ 0.65753453, 0.84279716, 0.88189818, 0.18987882, 0.49800668, 0.29656994, 0.39542769, 0.43155428, 0.77982853, 0.44955868, 0.22080219, 0.4807312 , 0.9288989 , 0.10956681, 0.73215416, 0.33184318, 0.10936647]) ans = array([ 0.98969952, 0.84044947, 0.63460516, 0.92042078, 0.75738113, 0.37976055])
Of course, this only makes sense if your data_id values ββare suitable for use as indices (i.e. non-negative integers and not huge ... presumably if they are large / sparse, you can initialize ans with np.unique(data_id) or something).
I must indicate that the data_id does not really need to be sorted.