Calculates the z score of each value in the sample, relative to the sample mean and standard deviation.
Parameters : | a : array_like
axis : int or None, optional
ddof : int, optional
|
---|---|
Returns : | zscore : array_like
|
Notes
This function preserves ndarray subclasses, and works also with matrices and masked arrays (it uses asanyarray instead of asarray for parameters).
Examples
>>> 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)
array([ 1.1273, -1.247 , -0.0552, 1.0923, 1.1664, -0.8559, 0.5786,
0.6748, -1.1488, -1.3324])
Computing along a specified axis, using n-1 degrees of freedom (ddof=1) to calculate the standard deviation:
>>> 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)
array([[-1.1649, -1.4319, -0.8554, -1.0189],
[-0.8661, -1.5035, -0.9737, -0.6154],
[-0.888 , -1.3817, -0.5461, -1.1156],
[-2.3043, -2.2014, -1.9921, -2.5241],
[-2.0773, -1.9212, -2.0506, -2.0328]])