scipp.nanstd#
- scipp.nanstd(x, dim=None, *, ddof)#
Compute the standard deviation of the input values ignoring NaN’s.
This function computes the standard deviation of the input values which is not related to the
x.variancesproperty but instead defined as\[\mathsf{nanstd}(x)^2 = \frac1{N - \mathsf{ddof}} \sum_{i=1}^{N}\, {(x_i - \bar{x})}^2\]where \(x_i\) are the non-NaN
valuesof the input and \(\bar{x}\) is the mean, seescipp.nanmean(). See theddofparameter description for what value to choose.- Parameters:
x (
scipp.typing.VariableLike) – Input data.dim (
Union[str,Iterable[str],None], default:None) – Dimension(s) along which to calculate the standard deviation. If not given, the standard deviation over a flattened version of the array is calculated.ddof (
int) –‘Delta degrees of freedom’. For sample standard deviations, set
ddof=1to obtain an unbiased estimator. For normally distributed variables, setddof=0to obtain a maximum likelihood estimate. Seenumpy.nanstd()for more details.In contrast to NumPy, this is a required parameter in Scipp to avoid potentially hard-to-find mistakes based on implicit assumptions about what the input data represents.
- Returns:
Same type as x– The standard deviation of the input values.- Raises:
scipp.VariancesError – If the input has variances.
scipp.DTypeError – If the input is binned or does otherwise not support computing standard deviations.
ValueError – If the input has masks. Mask out NaN’s and then use
scipp.std()instead.
See also
scipp.nanmeanCompute the arithmetic mean ignoring NaN’s.
scipp.nanvarCompute the variance, ignoring NaN’s.
scipp.stdCompute the standard deviation without special handling of NaN’s.
Examples
nanstdis available as a method:>>> x = sc.array(dims=['x'], values=[np.nan, 5, 2, 3]) >>> x.nanstd(ddof=0) <scipp.Variable> () float64 [dimensionless] 1.24722 >>> x.nanstd(ddof=1) <scipp.Variable> () float64 [dimensionless] 1.52753