bundles / scipy 1.17.1 / scipy / stats / _stats_py / zscore
function
scipy.stats._stats_py:zscore
source: /scipy/stats/_stats_py.py :2677
Signature
def zscore ( a , axis = 0 , ddof = 0 , nan_policy = propagate ) Summary
Compute the z score.
Extended Summary
Compute the z score of each value in the sample, relative to the sample mean and standard deviation.
Parameters
a: array_likeAn array like object containing the sample 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 z-scores computed for the non-nan values.
Returns
zscore: array_likeThe z-scores, standardized by mean and 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
zscore 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
import numpy as np a = np.array([ 0.7972, 0.0767, 0.4383, 0.7866, 0.8091, 0.1954, 0.6307, 0.6599, 0.1065, 0.0508]) from scipy import stats✓
stats.zscore(a)
✗b = np.array([[ 0.3148, 0.0478, 0.6243, 0.4608], [ 0.7149, 0.0775, 0.6072, 0.9656], [ 0.6341, 0.1403, 0.9759, 0.4064], [ 0.5918, 0.6948, 0.904 , 0.3721], [ 0.0921, 0.2481, 0.1188, 0.1366]])✓
stats.zscore(b, axis=1, ddof=1)
✗x = np.array([[25.11, 30.10, np.nan, 32.02, 43.15], [14.95, 16.06, 121.25, 94.35, 29.81]])✓
stats.zscore(x, axis=1, nan_policy='omit')
✗See also
- numpy.mean
Arithmetic average
- numpy.std
Arithmetic standard deviation
- scipy.stats.gzscore
Geometric standard score
Aliases
-
scipy.stats.zscore