scipp.std(x, dim=None, *, ddof)#

Compute the standard deviation of the input values.

This function computes the standard deviation of the input values which is not related to the x.variances property but instead defined as

\[\mathsf{std}(x)^2 = \frac1{N - \mathsf{ddof}} \sum_{i=1}^{N}\, {(x_i - \bar{x})}^2\]

where \(x_i\) are the unmasked values of the input and \(\bar{x}\) is the mean, see scipp.mean(). See the ddof parameter description for what value to choose.


Masks are broadcast to the shape of x. This can lead to a large temporary memory usage.

  • 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.std() 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.


Same type as x – The standard deviation of the input values.


See also


Compute the standard deviations from the stored variances of a scipp.Variable.


Compute the arithmetic mean.


Compute the variance.


Ignore NaN’s when calculating the standard deviation.


std is available as a method:

>>> x = sc.array(dims=['x'], values=[3, 5, 2, 3])
>>> x.std(ddof=0)
<scipp.Variable> ()    float64  [dimensionless]  1.08972
>>> x.std(ddof=1)
<scipp.Variable> ()    float64  [dimensionless]  1.25831

Select a dimension to reduce:

>>> x = sc.array(dims=['x', 'y'], values=[[1, 3, 6], [2, 7, 4]])
>>> x.std('y', ddof=0)
<scipp.Variable> (x: 2)    float64  [dimensionless]  [2.0548, 2.0548]
>>> x.std('x', ddof=0)
<scipp.Variable> (y: 3)    float64  [dimensionless]  [0.5, 2, 1]