def groupmean_d(x, d):
 x = np.asarray(x)
 nvars = (x.ndim + 1)
 sli = (([slice(None)] + ([None] * (nvars - 2))) + [slice(None)])
 return (((x[..., None] * d[sli]).sum(0) * 1.0) / d.sum(0))

def groupmean_d ( x , d ) : x = np . asarray ( x ) nvars = ( x . ndim + 1 ) sli = ( ( [ slice ( None ) ] + ( [ None ] * ( nvars - 2 ) ) ) + [ slice ( None ) ] ) return ( ( ( x [ ... , None ] * d [ sli ] ) . sum ( 0 ) * 1.0 ) / d . sum ( 0 ) )
groupmeans using dummy variables parameters x : array_like .