code: def labelmeanfilter_nd(y, x):
      # requires integer labels
      # from mailing list scipy-user 2009-02-11
      # adjusted for 2d x with column variables
  
      labelsunique = np.arange(np.max(y) + 1)
      labmeansdata = []
      labmeans = []
  
      for xx in x.T:
          labelmeans = np.array(
              ndimage.mean(xx, labels=y, index=labelsunique)
          )
          labmeansdata.append(labelmeans[y])
          labmeans.append(labelmeans)
      # group count:
      labelcount = np.array(
          ndimage.histogram(
              y,
              labelsunique[0],
              labelsunique[-1] + 1,
              1,
              labels=y,
              index=labelsunique,
          )
      )
  
      # returns array of lable/group counts and of label/group means
      #         and label/group means for each original observation
      return labelcount, np.array(labmeans), np.array(labmeansdata).T
  
file_path: statsmodels/statsmodels/sandbox/regression/try_catdata.py
imports: from statsmodels.compat.python import lrange
  import numpy
  from scipy import ndimage
label_desc: Use image node_id 2 for calling a global function with example usage: labelmeanfilter_nd(y, x) and returns: labelcount,  np,  np