def groupsstats_1d(y, x, labelsunique):
 labelmeans = np.array(ndimage.mean(x, labels=y, index=labelsunique))
 labelvars = np.array(ndimage.var(x, labels=y, index=labelsunique))
 return (labelmeans, labelvars)

def groupsstats_1d ( y , x , labelsunique ) : labelmeans = np . array ( ndimage . mean ( x , labels = y , index = labelsunique ) ) labelvars = np . array ( ndimage . var ( x , labels = y , index = labelsunique ) ) return ( labelmeans , labelvars )
use ndimage to get fast mean and variance .