scipy.stats.zscore

scipy.stats.zscore(a, axis=0, ddof=0, nan_policy=’propagate’)[source]

Compute the z score.

Compute the z score of each value in the sample, relative to the sample mean and standard deviation.

Parameters

a : array_like

An array like object containing the sample data.

axis :int or None, optional

Axis along which to operate. Default is 0. If None, compute over the whole array a.

ddof : int, optional

Degrees of freedom correction in the calculation of the standard deviation. Default is 0.

nan_policy :{‘propagate’, ‘raise’, ‘omit’}, optional

Defines how to handle when input contains nan. ‘propagate’ returns nan, ‘raise’ throws an error, ‘omit’ performs the calculations ignoring nan values. Default is ‘propagate’.

Returns

zscore:array_like

The 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).

Examples

  1. a = np.array([ 0.7972, 0.0767, 0.4383, 0.7866, 0.8091,
  2. 0.1954, 0.6307, 0.6599, 0.1065, 0.0508])
  3. from scipy import stats
  4. stats.zscore(a)

Computing along a specified axis, using n-1 degrees of freedom (ddof=1) to calculate the standard deviation:

  1. b = np.array([[ 0.3148, 0.0478, 0.6243, 0.4608],
  2. ... [ 0.7149, 0.0775, 0.6072, 0.9656],
  3. ... [ 0.6341, 0.1403, 0.9759, 0.4064],
  4. ... [ 0.5918, 0.6948, 0.904 , 0.3721],
  5. ... [ 0.0921, 0.2481, 0.1188, 0.1366]])
  6. stats.zscore(b, axis=1, ddof=1)

Previous topic

scipy.stats.zmap

Next topic

scipy.stats.wasserstein_distance

Quick search

  • © Copyright 2008-2019, The SciPy community.
  • Last updated on Dec 19, 2019.
  • Created using Sphinx 2.2.1.