code: def mode_in_range(a, axis=0, tol=1E-3):
      
      a_trunc = a // tol
      vals, counts = mode(a_trunc, axis)
      mask = (a_trunc == vals)
      # mean of each row
      return np.sum(a * mask, axis) / np.sum(mask, axis)
docs: Find the mode of values to within a certain range