code: def quantile(x, q, weights=None):
      
  
      # Initial check.
      x = np.atleast_1d(x)
      q = np.atleast_1d(q)
  
      # Quantile check.
      if np.any(q < 0.0) or np.any(q > 1.0):
          raise ValueError("Quantiles must be between 0. and 1.")
  
      if weights is None:
          # If no weights provided, this simply calls `np.percentile`.
          return np.percentile(x, list(100.0 * q))
      else:
          # If weights are provided, compute the weighted quantiles.
          weights = np.atleast_1d(weights)
          if len(x) != len(weights):
              raise ValueError("Dimension mismatch: len(weights) != len(x).")
          idx = np.argsort(x)  # sort samples
          sw = weights[idx]  # sort weights
          cdf = np.cumsum(sw)[:-1]  # compute CDF
          cdf /= cdf[-1]  # normalize CDF
          cdf = np.append(0, cdf)  # ensure proper span
          quantiles = np.interp(q, cdf, x[idx]).tolist()
          return quantiles
docs: Compute (weighted) quantiles from an input set of samples.
  
      Parameters
      ----------
      x : `~numpy.ndarray` with shape (nsamps,)
          Input samples.
  
      q : `~numpy.ndarray` with shape (nquantiles,)
         The list of quantiles to compute from `[0., 1.]`.
  
      weights : `~numpy.ndarray` with shape (nsamps,), optional
          The associated weight from each sample.
  
      Returns
      -------
      quantiles : `~numpy.ndarray` with shape (nquantiles,)
          The weighted sample quantiles computed at `q`.