Warning

You are reading the documentation related to the development version. Go here if you are looking for the documentation of the stable release.

spectrochempy.std

std(dataset, dim=None, dtype=None, ddof=0, keepdims=False)[source]

Compute the standard deviation along the specified axis.

Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.

Parameters
  • dataset (array_like) – Calculate the standard deviation of these values.

  • dim (None or int or dimension name , optional) – Dimension or dimensions along which to operate. By default, flattened input is used.

  • dtype (dtype, optional) – Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.

  • ddof (int, optional) – Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof , where N represents the number of elements. By default ddof is zero.

  • keepdims (bool, optional) – If this is set to True, the dimensions which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

std – A new array containing the standard deviation.

See also

var

Variance values along axis.

mean

Compute the arithmetic mean along the specified axis.

Notes

The standard deviation is the square root of the average of the squared deviations from the mean, i.e., std = sqrt(mean(abs(x - x.mean())**2)) .

The average squared deviation is normally calculated as x.sum() / N , where N = len(x) . If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of the infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables. The standard deviation computed in this function is the square root of the estimated variance, so even with ddof=1 , it will not be an unbiased estimate of the standard deviation per se.

Note that, for complex numbers, std takes the absolute value before squaring, so that the result is always real and nonnegative. For floating-point input, the std is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.

Examples

>>> nd = scp.read('irdata/nh4y-activation.spg')
>>> nd
NDDataset: [float64] a.u. (shape: (y:55, x:5549))
>>> scp.std(nd)
<Quantity(0.807972021, 'absorbance')>
>>> scp.std(nd, keepdims=True)
NDDataset: [float64] a.u. (shape: (y:1, x:1))
>>> m = scp.std(nd, dim='y')
>>> m
NDDataset: [float64] a.u. (size: 5549)
>>> m.data
array([ 0.08521,  0.08543, ...,    0.251,   0.2537])