code: def group_sums(x, group, use_bincount=True):
      """simple bincount version, again
  
      group : ndarray, integer
          assumed to be consecutive integers
  
      no dtype checking because I want to raise in that case
  
      uses loop over columns of x
  
      for comparison, simple python loop
      """
      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:
          # re-label groups or bincount takes too much memory
          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[group == cat].sum(0)
          return result
  
imports: from statsmodels.compat.python import lrange, lzip
  import numpy
  import pandas
  import statsmodels.tools.data
  from pandas import Index, MultiIndex
label_desc: Use image node_id 2 for calling a global function with example usage: group_sums(x, group, use_bincount) and returns: np, result