code: def smoothed_histogram_from_samples(
      x, bins=None, nbins=256, normalized=False
  ):
      """Smooth histogram corresponding to density underlying the samples in `x`
  
      Parameters
      ----------
      x: array of shape(n_samples)
         input data
      bins: array of shape(nbins+1), optional
         the bins location
      nbins: int, optional
         the number of bins of the resulting histogram
      normalized: bool, optional
         if True, the result is returned as a density value
  
      Returns
      -------
      h: array of shape (nbins)
         the histogram
      bins: array of shape(nbins+1),
         the bins location
      """
      from scipy.ndimage import gaussian_filter1d
  
      # first define the bins
      if bins is None:
          h, bins = np.histogram(x, nbins)
          bins = bins.mean() + 1.2 * (bins - bins.mean())
          h, bins = np.histogram(x, bins)
  
      # possibly normalize to density
      h = 1.0 * h
      dc = bins[1] - bins[0]
      if normalized:
          h /= dc * h.sum()
  
      # define the optimal width
      sigma = x.std() / (dc * np.exp(0.2 * np.log(x.size)))
  
      # smooth the histogram
      h = gaussian_filter1d(h, sigma, mode="constant")
  
      return h, bins
  
file_path: nipy/nipy/algorithms/statistics/empirical_pvalue.py
imports: import numpy
  import scipy.stats
  from numpy.linalg import pinv
label_desc: Use image node_id 8 for calling a global function with example usage: smoothed_histogram_from_samples(x, bins, nbins, normalized) and returns: h,  bins