mindspore.ops.std

mindspore.ops.std(input, axis=None, ddof=0, keepdims=False)[source]

Returns the standard-deviation of each row of the input Tensor by default, or it can calculate them in specified dimension axis. If axis is a list of dimensions, reduce over all of them.

Note

If ddof is 0, 1, True or False, the supported device is only Ascend and CPU. In other cases, the supported device is Ascend, GPU and CPU.

Parameters
  • input (Tensor[Number]) – Input Tensor with a dtype of number.Number, its shape should be \((N, *)\) where \(*\) means any number of additional dims.

  • axis (Union[int, tuple(int)], optional) – The dimensions to reduce. Only constant value is allowed. Must be in the range [-rank(input), rank(input)). Default: None, reduce all dimensions.

  • ddof (Union[int, bool], optional) – Means Delta Degrees of Freedom. If ddof is an integer, the divisor used in calculations is \(N - ddof\), where \(N\) represents the number of elements. If ddof is True, will use the Bessel correction unbiased estimation. If ddof is False, will through the biased estimation to calculate the standard deviation. Default: 0.

  • keepdims (bool, optional) – Whether the output Tensor has dim retained or not. If true, keep these reduced dimensions and the length is 1. If false, don’t keep these dimensions. Default: False.

Returns

Tensor, the standard deviation. Suppose the shape of input is \((x_0, x_1, ..., x_R)\):

  • If axis is () and keepdims is set to False, returns a 0-D Tensor, indicating the standard deviation of all elements in input.

  • If axis is int 1 and keepdims is set to False, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).

  • If axis is tuple(int) or list(int), e.g. (1, 2) and keepdims is set to False, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If axis is not one of the following: None, int, tuple.

  • TypeError – If keepdims is not a bool.

  • ValueError – If axis is out of range.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32)
>>> output = ms.ops.std(input, 1, 2, True)
>>> print(output)
[[1.5811388]
 [7.3824115]]