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.variances property 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 values of the input and \(\bar{x}\) is the mean, see scipp.nanmean(). See the ddof parameter description for what value to choose.

Parameters:
  • x (scipp.typing.VariableLike) – Input data.

  • dim (Union[str, Sequence[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=1 to obtain an unbiased estimator. For normally distributed variables, set ddof=0 to obtain a maximum likelihood estimate. See numpy.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:

See also

scipp.nanmean

Compute the arithmetic mean ignoring NaN’s.

scipp.nanvar

Compute the variance, ignoring NaN’s.

scipp.std

Compute the standard deviation without special handling of NaN’s.

Examples

nanstd is 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