code: def discretize(X, method="ef", nbins=None):
      """
      Discretize `X`
  
      Parameters
      ----------
      bins : int, optional
          Number of bins.  Default is floor(sqrt(N))
      method : str
          "ef" is equal-frequency binning
          "ew" is equal-width binning
  
      Examples
      --------
      """
      nobs = len(X)
      if nbins is None:
          nbins = np.floor(np.sqrt(nobs))
      if method == "ef":
          discrete = np.ceil(nbins * stats.rankdata(X) / nobs)
      if method == "ew":
          width = np.max(X) - np.min(X)
          width = np.floor(width / nbins)
          svec, ivec = stats.fastsort(X)
          discrete = np.zeros(nobs)
          binnum = 1
          base = svec[0]
          discrete[ivec[0]] = binnum
          for i in range(1, nobs):
              if svec[i] < base + width:
                  discrete[ivec[i]] = binnum
              else:
                  base = svec[i]
                  binnum += 1
                  discrete[ivec[i]] = binnum
      return discrete
  
file_path: statsmodels/statsmodels/sandbox/infotheo.py
imports: from statsmodels.compat.python import lzip, lmap
  from scipy import stats
  import numpy
  from matplotlib import pyplot
  from scipy.special import logsumexp
label_desc: Use image node_id 3 for calling a global function with example usage: discretize(X, method, nbins) and returns: discrete