import numpy_indexed as npi x = np.concatenate([x1,x2,x3,x4]) y = np.concatenate([y1,y2,y3,y4]) x_unique, y_mean = npi.group_by(x).mean(y)