def sum_outer_product_balanced(x, n_groups):
 xrs = x.reshape((-1), n_groups, order='F')
 return np.dot(xrs, xrs.T)

def sum_outer_product_balanced ( x , n_groups ) : xrs = x . reshape ( ( - 1 ) , n_groups , order = 'F' ) return np . dot ( xrs , xrs . T )
sum outerproduct dot over individuals where x_i is .