code: def quantize(image, nlevels):
      
      tmp = np.array(image // (1.0 / nlevels), dtype='i1')
      return tmp.clip(0, nlevels - 1)
docs: Quantize an image into integers 0, 1, ..., nlevels - 1.
  
      image   -- a numpy array of type float, range [0, 1]
      nlevels -- an integer