Measurement analysis
Estimate uncertainty for means computed from repeated measurements.
SciPy · Function
Computes the standard error of the mean for an array, either overall or along a chosen axis. It supports degrees-of-freedom adjustment, NaN policies, and dimension preservation.
The function computes the standard error of the mean for an array or for each slice along a selected axis. It can flatten the input, adjust the variance degrees of freedom, control NaN handling, and optionally retain reduced dimensions.
scipy.stats.sem(a, axis=0, ddof=1, nan_policy='propagate', *, keepdims=False)| Name | Type | Description |
|---|---|---|
a | array_like | Array-like values for which to calculate the standard error. |
axis | int or None | Axis along which to calculate the statistic; None ravels the input. Default: 0. |
ddof | int | Degrees-of-freedom adjustment for the variance. Default: 1. |
nan_policy | {'propagate', 'raise', 'omit'} | NaN handling policy: 'propagate', 'raise', or 'omit'. Default: 'propagate'. |
keepdims | bool | Whether reduced axes are retained with size one. Default: False. |
ndarray or float: the standard error of the mean in the sample(s), along the input axis.
sem measures uncertainty in a sample mean rather than returning the mean itself.a may be an array-like collection of values.axis=None computes a single statistic over all input elements.ddof controls the degrees-of-freedom adjustment used for the variance underlying the SEM.nan_policy determines whether NaNs propagate, raise an exception, or are omitted.import numpy as np
from scipy import stats
a = np.arange(20).reshape(5, 4)
print(stats.sem(a))
print(stats.sem(a, axis=None, ddof=0))Computes column-wise standard errors, then computes one standard error over all values with population-style degrees of freedom.
Estimate uncertainty for means computed from repeated measurements.
Compute one SEM per row or column in a multidimensional dataset.
Handle missing observations explicitly during statistical aggregation.
scipy.stats.sem compute, and what are its key defaults?scipy.stats.sem calculates the standard error of the mean for the input values. By default it reduces along axis 0, uses ddof=1, and propagates NaNs.
Follow-up: How do you calculate one SEM for the entire array? Use axis=None, which ravels the input before computing the statistic.
axis, ddof, and keepdims affect the result?Set axis=None to compute across the whole input after flattening it. Set ddof=0 when the variance calculation should use no degrees-of-freedom subtraction.
Follow-up: How would you preserve reduced axes? Set keepdims=True, so the output retains dimensions with length one.
nan_policy handle missing values?nan_policy accepts 'propagate', 'raise', or 'omit'. These respectively return NaNs, raise an error, or ignore NaNs during calculation.
Follow-up: Which option is appropriate when missing values should not silently affect the result? Use 'raise' to fail explicitly when NaNs are present.
scipy.stats.tmeanscipy.stats.tstdscipy.stats.describe