code: def reverseHistogram(data,bins=None):
      
      if bins is None: bins = np.arange(data.max()+2)
      hist, edges = np.histogram(data, bins=bins)
      digi = np.digitize(data.flat,bins=np.unique(data)).argsort()
      rev = np.hstack( (len(edges), len(edges) + np.cumsum(hist), digi) )
      return hist,edges,rev
docs: Bins data using np.histogram and calculates the
      reverse indices for the entries like IDL.
      Parameters:
      data  : data to pass to np.histogram
      bins  : bins to pass to np.histogram 
      Returns: 
      hist  : bin content output by np.histogram 
      edges : edges output from np.histogram 
      rev   : reverse indices of entries in each bin 
      Using Reverse Indices: 
          h,e,rev = histogram(data, bins=bins) 
          for i in range(h.size):  
              if rev[i] != rev[i+1]: 
                  # data points were found in this bin, get their indices
                  indices = rev[ rev[i]:rev[i+1] ] 
                  # do calculations with data[indices] ...