nlcpy.std
- nlcpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=nlcpy._NoValue)
Computes 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
- aarray_like
Calculate the standard deviation of these values.
- axisNone or int, optional
Axis along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
- dtypedtype, 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.
- outndarray, optional
Alternative output array in which to place the result. It must have the same shape as the expected output but the type (of the calculated values) will be cast if necessary.
- ddofint, optional
Means Delta Degrees of Freedom. The divisor used in calculations is
N - ddof
, whereN
represents the number of elements. By default, ddof is zero.- keepdimsbool, optional
If this is set to True, the axis 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
- standard_deviationndarray, see dtype parameter above.
If out is None, return a new array containing the standard deviation, otherwise return a reference to the output array.
参考
var
Computes the variance along the specified axis.
mean
Computes the arithmetic mean along the specified axis.
nanmean
Computes the arithmetic mean along the specified axis, ignoring NaNs.
nanstd
Computes the standard deviation along the specified axis, while ignoring NaNs.
nanvar
Computes the variance along the specified axis, while ignoring NaNs.
注釈
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
, whereN = len(x)
. If, however,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 withddof=1
, it will not be an unbiased estimate of the standard deviation per se.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.
制限事項
If axis is neither a scalar nor None : NotImplementedError occurs.
For complex numbers : NotImplementedError occurs.
Examples
>>> import nlcpy as vp >>> a = vp.array([[1, 2], [3, 4]]) >>> vp.std(a) array(1.11803399) >>> vp.std(a, axis=0) array([1., 1.]) >>> vp.std(a, axis=1) array([0.5, 0.5])
In single precision, std() can be inaccurate:
>>> a = vp.zeros((2, 512*512), dtype=vp.float32) >>> a[0, :] = 1.0 >>> a[1, :] = 0.1 >>> vp.std(a) array(0.45002034, dtype=float32)
Computing the standard deviation in float64 is more accurate:
>>> vp.std(a, dtype=vp.float64) array(0.45)