def group_sums(x, group, use_bincount=True):
 x = np.asarray(x)
 if (x.ndim == 1):
  x = x[:, None]
 elif ((x.ndim > 2) and use_bincount):
  raise ValueError('not implemented yet')
 if use_bincount:
  if (np.max(group) > (2 * x.shape[0])):
   group = pd.factorize(group)[0]
  return np.array([np.bincount(group, weights=x[:, col]) for col in range(x.shape[1])])
 else:
  uniques = np.unique(group)
  result = np.zeros(([len(uniques)] + list(x.shape[1:])))
  for (ii, cat) in enumerate(uniques):
   result[ii] = x[(g == cat)].sum(0)
  return result

def group_sums ( x , group , use_bincount = True ) : x = np . asarray ( x ) if ( x . ndim == 1 ) : x = x [ : , None ] elif ( ( x . ndim > 2 ) and use_bincount ) : raise ValueError ( 'not implemented yet' ) if use_bincount : if ( np . max ( group ) > ( 2 * x . shape [ 0 ] ) ) : group = pd . factorize ( group ) [ 0 ] return np . array ( [ np . bincount ( group , weights = x [ : , col ] ) for col in range ( x . shape [ 1 ] ) ] ) else : uniques = np . unique ( group ) result = np . zeros ( ( [ len ( uniques ) ] + list ( x . shape [ 1 : ] ) ) ) for ( ii , cat ) in enumerate ( uniques ) : result [ ii ] = x [ ( g == cat ) ] . sum ( 0 ) return result
sum x for each group .