Free tools Windows power users keep installed
One-click scans. No signup required.
Use scipy.stats.zscore to express each value as its distance from a selected mean in standard-deviation units. The key choices are which axis defines the comparison group, whether to use the default population-style standard deviation or the ddof=1 correction, and how to handle NaNs.
Calculate z-scores with scipy.stats.zscore
The function computes standardized scores from an array-like input. For each value, it subtracts the relevant mean and divides by the relevant standard deviation. A positive score is above that mean; a negative score is below it.
As an Amazon Associate I earn from qualifying purchases.
import numpy as np
from scipy import stats
a = np.array([10, 12, 14, 16, 18])
z = stats.zscore(a)
print(z)
This uses the documented defaults: axis=0, ddof=0, and nan_policy='propagate'. The output contains z-scores corresponding to the input values. See the SciPy zscore API reference for the signature and examples.
Choose the axis that matches the comparison group
For a multidimensional array, the axis determines which slices are standardized. Decide which observations should share a mean and standard deviation before choosing the axis; axis is a statistical choice, not just an output-shape setting.
#1 Best Overall
axis=0(the default) computes statistics along axis 0, standardizing values within the corresponding slices.axis=1computes along axis 1. The SciPy reference demonstrates this setting withddof=1.axis=Nonecomputes the statistics over the entire array as one collection.
For example, if rows represent different people and columns represent measurements, choose the axis according to whether each measurement should be compared across people or each person’s measurements should be compared with one another.
Set ddof for the standard-deviation convention you need
ddof adjusts the degrees of freedom used in the standard deviation calculation. Its default is 0. When you intend the sample standard deviation convention using n−1 degrees of freedom, set ddof=1:
Rank #2
- This guide is a perfect overview for the topics covered in introductory statistics courses.
z_sample = stats.zscore(a, ddof=1)
Changing ddof changes the standard deviation used as the divisor and therefore changes the resulting scores. Make the choice explicit when it matters to interpreting or reproducing an analysis.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesChoose how NaN values are handled
The default nan_policy='propagate' propagates NaNs through the calculation. The API also supports two alternatives:
Rank #3
nan_policy='raise'raises an error if NaNs are present.nan_policy='omit'excludes NaNs from the calculations for non-NaN values. NaN positions in the output remain NaN.
a_with_nan = np.array([10.0, 12.0, np.nan, 16.0])
z_omit = stats.zscore(a_with_nan, nan_policy='omit')
Select a policy deliberately: omission allows scores for observed values to be calculated without the missing entries affecting those calculations, while preserving the missing positions in the result.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

