bundles / scipy 1.17.1 / scipy / stats / _stats_py / gzscore
function
scipy.stats._stats_py:gzscore
source: /scipy/stats/_stats_py.py :2763
Signature
def gzscore ( a , * , axis = 0 , ddof = 0 , nan_policy = propagate ) Summary
Compute the geometric standard score.
Extended Summary
Compute the geometric z score of each strictly positive value in the sample, relative to the geometric mean and standard deviation. Mathematically the geometric z score can be evaluated as
gzscore = log(a/gmu) / log(gsigma)where gmu (resp. gsigma) is the geometric mean (resp. standard deviation).
Parameters
a: array_likeSample data.
axis: int or None, optionalAxis along which to operate. Default is 0. If None, compute over the whole array
a.ddof: int, optionalDegrees of freedom correction in the calculation of the standard deviation. Default is 0.
nan_policy: {'propagate', 'raise', 'omit'}, optionalDefines how to handle when input contains nan. 'propagate' returns nan, 'raise' throws an error, 'omit' performs the calculations ignoring nan values. Default is 'propagate'. Note that when the value is 'omit', nans in the input also propagate to the output, but they do not affect the geometric z scores computed for the non-nan values.
Returns
gzscore: array_likeThe geometric z scores, standardized by geometric mean and geometric standard deviation of input array
a.
Notes
This function preserves ndarray subclasses, and works also with matrices and masked arrays (it uses asanyarray instead of asarray for parameters).
Array API Standard Support
gzscore has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ✅ ✅ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
Draw samples from a log-normal distribution:import numpy as np from scipy.stats import zscore, gzscore import matplotlib.pyplot as plt✓
rng = np.random.default_rng() mu, sigma = 3., 1. # mean and standard deviation x = rng.lognormal(mu, sigma, size=500)✓
fig, ax = plt.subplots()
✓ax.hist(x, 50)
✗plt.show()
✓
fig, ax = plt.subplots()
✓ax.hist(zscore(x), 50)
✗plt.show()
✓
fig, ax = plt.subplots()
✓ax.hist(gzscore(x), 50)
✗plt.show()
✓
See also
Aliases
-
scipy.stats.gzscore