dpnp.std

dpnp.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True, mean=None, correction=None)

Compute the standard deviation along the specified axis.

For full documentation refer to numpy.std.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axis ({None, int, tuple of ints}, optional) --

    Axis or axes along which the standard deviations must be computed. If a tuple of unique integers is given, the standard deviations are computed over multiple axes. If None, the standard deviation is computed over the entire array.

    Default: None.

  • dtype ({None, str, dtype object}, optional) --

    Type to use in computing the standard deviation. By default, if a has a floating-point data type, the returned array will have the same data type as a. If a has a boolean or integral data type, the returned array will have the default floating point data type for the device where input array a is allocated.

    Default: None.

  • out ({None, dpnp.ndarray, usm_ndarray}, 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.

    Default: None.

  • ddof ({int, float}, optional) --

    Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N corresponds to the total number of elements over which the standard deviation is calculated.

    Default: 0.0.

  • keepdims ({None, bool}, optional) --

    If True, the reduced axes (dimensions) are included in the result as singleton dimensions, so that the returned array remains compatible with the input array according to Array Broadcasting rules. Otherwise, if False, the reduced axes are not included in the returned array.

    Default: False.

  • mean ({dpnp.ndarray, usm_ndarray}, optional) --

    Provide the mean to prevent its recalculation. The mean should have a shape as if it was calculated with keepdims=True. The axis for the calculation of the mean should be the same as used in the call to this std function.

    Default: None.

  • correction ({None, int, float}, optional) --

    Array API compatible name for the ddof parameter. Only one of them can be provided at the same time.

    Default: None.

Returns:

out -- An array containing the standard deviations. If the standard deviation was computed over the entire array, a zero-dimensional array is returned.

Return type:

dpnp.ndarray

Limitations

Parameters where is only supported with its default value. Otherwise NotImplementedError exception will be raised.

Notes

There are several common variants of the array standard deviation calculation. Assuming the input a is a one-dimensional array and mean is either provided as an argument or computed as a.mean(), DPNP computes the standard deviation of an array as:

N = len(a)
d2 = abs(a - mean)**2  # abs is for complex `a`
var = d2.sum() / (N - ddof)  # note use of `ddof`
std = var**0.5

Different values of the argument ddof are useful in different contexts. The default ddof=0 corresponds with the expression:

\[\sqrt{\frac{\sum_i{|a_i - \bar{a}|^2 }}{N}}\]

which is sometimes called the "population standard deviation" in the field of statistics because it applies the definition of standard deviation to a as if a were a complete population of possible observations.

Many other libraries define the standard deviation of an array differently, e.g.:

\[\sqrt{\frac{\sum_i{|a_i - \bar{a}|^2 }}{N - 1}}\]

In statistics, the resulting quantity is sometimes called the "sample standard deviation" because if a is a random sample from a larger population, this calculation provides the square root of an unbiased estimate of the variance of the population. The use of \(N-1\) in the denominator is often called "Bessel's correction" because it corrects for bias (toward lower values) in the variance estimate introduced when the sample mean of a is used in place of the true mean of the population. The resulting estimate of the standard deviation is still biased, but less than it would have been without the correction. For this quantity, use ddof=1.

Note that, for complex numbers, the absolute value is taken before squaring, so that the result is always real and non-negative.

See also

dpnp.ndarray.std

corresponding function for ndarrays.

dpnp.var

Compute the variance along the specified axis.

dpnp.mean

Compute the arithmetic mean along the specified axis.

dpnp.nanmean

Compute the arithmetic mean along the specified axis, ignoring NaNs.

dpnp.nanstd

Compute the standard deviation along the specified axis, while ignoring NaNs.

dpnp.nanvar

Compute the variance along the specified axis, while ignoring NaNs.

Examples

>>> import dpnp as np
>>> a = np.array([[1, 2], [3, 4]])
>>> np.std(a)
array(1.11803399)
>>> np.std(a, axis=0)
array([1., 1.])
>>> np.std(a, axis=1)
array([0.5, 0.5])

Using the mean keyword to save computation time:

>>> a = np.array([[14, 8, 11, 10], [7, 9, 10, 11], [10, 15, 5, 10]])
>>> mean = np.mean(a, axis=1, keepdims=True)
>>> np.std(a, axis=1, mean=mean)
array([2.16506351, 1.47901995, 3.53553391])