code: def null_to_p(test_values, null_array, alternative="two-sided"):
      """Return p-value for test value(s) against null array.
  
      Parameters
      ----------
      test_values : :obj:`int`, :obj:`float`, or array_like of shape (n_samples,)
          Value(s) for which to determine p-value.
      null_array : array_like of shape (n_iters,)
          Null distribution against which test_values is compared.
      alternative : {'two-sided', 'larger', 'smaller'}, default='two-sided'
          Whether to compare value against null distribution in a two-sided
          or one-sided ('larger' or 'smaller') manner. If 'larger', then higher
          values for the test_values are more significant. If 'smaller', then
          lower values for the test_values are more significant.
  
      Returns
      -------
      p_values : :obj:`float` or array_like of shape (n_samples,)
          P-value(s) associated with the test value when compared against the
          null distribution. Return type matches input type (i.e., a float if
          test_values is a single float, and an array if test_values is an
          array).
  
      Notes
      -----
      P-values are clipped based on the number of elements in the null array.
      Therefore no p-values of 0 or 1 should be produced.
  
      This function assumes that the null distribution for two-sided tests is
      symmetric around zero.
      """
      if alternative not in {"two-sided", "larger", "smaller"}:
          raise ValueError(
              'Argument "alternative" must be one of '
              '["two-sided", "larger", "smaller"]'
          )
  
      return_first = isinstance(test_values, (float, int))
      test_values = np.atleast_1d(test_values)
      null_array = np.array(null_array)
  
      # For efficiency's sake, if there are more than 1000 values, pass only the
      # unique values through percentileofscore(), and then reconstruct.
      if len(test_values) > 1000:
          reconstruct = True
          test_values, uniq_idx = np.unique(
              test_values, return_inverse=True
          )
      else:
          reconstruct = False
  
      def compute_p(t, null):
          null = np.sort(null)
          idx = np.searchsorted(null, t, side="left").astype(float)
          return 1 - idx / len(null)
  
      if alternative == "two-sided":
          # Assumes null distribution is symmetric around 0
          p = compute_p(np.abs(test_values), np.abs(null_array))
      elif alternative == "smaller":
          p = compute_p(test_values * -1, null_array * -1)
      else:
          p = compute_p(test_values, null_array)
  
      # ensure p_value in the following range:
      # smallest_value <= p_value <= (1.0 - smallest_value)
      smallest_value = np.maximum(
          np.finfo(float).eps, 1.0 / len(null_array)
      )
      result = np.maximum(
          smallest_value, np.minimum(p, 1.0 - smallest_value)
      )
  
      if reconstruct:
          result = result[uniq_idx]
  
      return result[0] if return_first else result
  
file_path: nilearn/nilearn/mass_univariate/_utils.py
imports: import numpy
  from scipy import linalg
  from scipy.ndimage import label
label_desc: Use image node_id 2 for calling a global function with example usage: null_to_p(test_values, null_array, alternative) and returns: unknown, unknown