std

std(x: array, /, *, axis: int | Tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) array

Calculates the standard deviation of the input array x.

Special Cases

Let N equal the number of elements over which to compute the standard deviation.

  • If N - correction is less than or equal to 0, the standard deviation is NaN.

  • If x_i is NaN, the standard deviation is NaN (i.e., NaN values propagate).

Parameters:
  • x (array) – input array. Should have a floating-point data type.

  • axis (Optional[Union[int, Tuple[int, ...]]]) – axis or axes along which standard deviations must be computed. By default, the standard deviation must be computed over the entire array. If a tuple of integers, standard deviations must be computed over multiple axes. Default: None.

  • correction (Union[int, float]) – degrees of freedom adjustment. Setting this parameter to a value other than 0 has the effect of adjusting the divisor during the calculation of the standard deviation according to N-c where N corresponds to the total number of elements over which the standard deviation is computed and c corresponds to the provided degrees of freedom adjustment. When computing the standard deviation of a population, setting this parameter to 0 is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample standard deviation, setting this parameter to 1 is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel’s correction). Default: 0.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

Returns:

out (array) – if the standard deviation was computed over the entire array, a zero-dimensional array containing the standard deviation; otherwise, a non-zero-dimensional array containing the standard deviations. The returned array must have the same data type as x.

Note

While this specification recommends that this function only accept input arrays having a floating-point data type, specification-compliant array libraries may choose to accept input arrays having an integer data type. While mixed data type promotion is implementation-defined, if the input array x has an integer data type, the returned array must have the default floating-point data type.