code: def _downsample_array(col: np.array, target: int, random_state: int=0,
                        replace: bool = True, inplace: bool=False):
      
      np.random.seed(random_state)
      cumcounts = col.cumsum()
      if inplace:
          col[:] = 0
      else:
          col = np.zeros_like(col)
      total = cumcounts[-1]
      sample = np.random.choice(total, target, replace=replace)
      sample.sort()
      geneptr = 0
      for count in sample:
          while count >= cumcounts[geneptr]:
              geneptr += 1
          col[geneptr] += 1
      return col
docs: Evenly reduce counts in cell to target amount.
  
      This is an internal function and has some restrictions:
  
      * `dtype` of col must be an integer (i.e. satisfy issubclass(col.dtype.type, np.integer))
      * total counts in cell must be less than target