code: def ztest(
      x1,
      x2=None,
      value=0,
      alternative="two-sided",
      usevar="pooled",
      ddof=1.0,
  ):
      """test for mean based on normal distribution, one or two samples
  
      In the case of two samples, the samples are assumed to be independent.
  
      Parameters
      ----------
      x1 : array_like, 1-D or 2-D
          first of the two independent samples
      x2 : array_like, 1-D or 2-D
          second of the two independent samples
      value : float
          In the one sample case, value is the mean of x1 under the Null
          hypothesis.
          In the two sample case, value is the difference between mean of x1 and
          mean of x2 under the Null hypothesis. The test statistic is
          `x1_mean - x2_mean - value`.
      alternative : str
          The alternative hypothesis, H1, has to be one of the following
  
             'two-sided': H1: difference in means not equal to value (default)
             'larger' :   H1: difference in means larger than value
             'smaller' :  H1: difference in means smaller than value
  
      usevar : str, 'pooled' or 'unequal'
          If ``pooled``, then the standard deviation of the samples is assumed to be
          the same. If ``unequal``, then the standard deviation of the sample is
          assumed to be different.
      ddof : int
          Degrees of freedom use in the calculation of the variance of the mean
          estimate. In the case of comparing means this is one, however it can
          be adjusted for testing other statistics (proportion, correlation)
  
      Returns
      -------
      tstat : float
          test statistic
      pvalue : float
          pvalue of the t-test
  
      Notes
      -----
      usevar can be pooled or unequal in two sample case
  
      """
      # TODO: this should delegate to CompareMeans like ttest_ind
      #       However that does not implement ddof
  
      # usevar can be pooled or unequal
  
      if usevar not in {"pooled", "unequal"}:
          raise NotImplementedError(
              'usevar can only be "pooled" or "unequal"'
          )
  
      x1 = np.asarray(x1)
      nobs1 = x1.shape[0]
      x1_mean = x1.mean(0)
      x1_var = x1.var(0)
  
      if x2 is not None:
          x2 = np.asarray(x2)
          nobs2 = x2.shape[0]
          x2_mean = x2.mean(0)
          x2_var = x2.var(0)
          if usevar == "pooled":
              var = nobs1 * x1_var + nobs2 * x2_var
              var /= nobs1 + nobs2 - 2 * ddof
              var *= 1.0 / nobs1 + 1.0 / nobs2
          elif usevar == "unequal":
              var = x1_var / (nobs1 - ddof) + x2_var / (nobs2 - ddof)
      else:
          var = x1_var / (nobs1 - ddof)
          x2_mean = 0
  
      std_diff = np.sqrt(var)
      # stat = x1_mean - x2_mean - value
      return _zstat_generic(
          x1_mean, x2_mean, std_diff, alternative, diff=value
      )
  
imports: import numpy
  from scipy import stats
  from statsmodels.tools.decorators import cache_readonly
label_desc: Use image node_id 9 for calling a global function with example usage: ztest(x1, x2, value, alternative, usevar, ddof) and returns: _zstat_generic