# scipp.var#

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

Compute the variance of the input values.

This function computes the variance of the input values which is not the same as the x.variances property but instead defined as

$\mathsf{var}(x) = \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.

Note

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

Parameters:
Returns:

Same type as x – The variance of the input values.

Raises:

scipp.variances

Extract the stored variances of a scipp.Variable.

scipp.mean

Compute the arithmetic mean.

scipp.std

Compute the standard deviation.

scipp.nanvar

Ignore NaN’s when calculating the variance.

Examples

var is available as a method:

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


Select a dimension to reduce:

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