code: def _pval_from_histogram(T, H0, tail):
      """Get p-values from stats values given an H0 distribution.
  
      For each stat compute a p-value as percentile of its statistics
      within all statistics in surrogate data
      """
      # from pct to fraction
      if tail == -1:  # up tail
          pval = np.array([np.mean(H0 <= t) for t in T])
      elif tail == 1:  # low tail
          pval = np.array([np.mean(H0 >= t) for t in T])
      else:  # both tails
          pval = np.array([np.mean(abs(H0) >= abs(t)) for t in T])
  
      return pval
  
imports: import numpy
  from scipy import ndimage, sparse
  from scipy.sparse.csgraph import connected_components
  from scipy.stats import f
  from scipy.stats import t
  from ..fixes import has_numba, jit
  from ..parallel import parallel_func
  from ..source_estimate import MixedSourceEstimate, SourceEstimate, VolSourceEstimate
  from ..source_space import SourceSpaces
  from ..utils import ProgressBar, _check_option, _pl, _validate_type, check_random_state, logger, split_list, verbose, warn
  from .parametric import f_oneway, ttest_1samp_no_p
label_desc: Use image node_id 18 for calling a global function with example usage: _pval_from_histogram(T, H0, tail) and returns: pval