def sum_outer_product_loop(x, group_iter):
 mom = 0
 for g in group_iter():
  x_g = x[g]
  mom += np.outer(x_g, x_g)
 return mom

def sum_outer_product_loop ( x , group_iter ) : mom = 0 for g in group_iter ( ) : x_g = x [ g ] mom += np . outer ( x_g , x_g ) return mom
sum outerproduct dot over individuals loop version .