mindspore.mint.std

View Source On AtomGit
mindspore.mint.std(input, dim=None, *, correction=1, keepdim=False)[source]

Calculate the standard deviation over specified dimension(s).

The standard deviation (\(\sigma\)) is calculated as:

\[\sigma =\sqrt{\frac{1}{N-\delta N}\sum_{j-1}^{N-1}\left(s e l f_{i j}-\overline{x_{i}}\right)^{2}}\]

where \(x\) is the sample set of elements, \(\bar{x}\) is the sample mean, \(N\) is the number of samples and \(\delta N\) is the correction.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – The input tensor.

  • dim (None, int, tuple(int), optional) – Specify the dimension. If None , calculate all elements. Default None.

Keyword Arguments
  • correction (int, optional) – The difference between the sample size and sample degrees of freedom. Default to Bessel’s correction. Default 1.

  • keepdim (bool, optional) – Whether the output tensor has dim retained. Default False.

Returns

Tensor

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> input = mindspore.tensor([[1, 2, 3], [-1, 1, 4]], mindspore.float32)
>>> mindspore.mint.std(input, dim=1, correction=1, keepdim=False)
Tensor(shape=[2], dtype=Float32, value= [ 1.00000000e+00,  2.51661134e+00])
>>> mindspore.mint.std(input, dim=1, correction=1, keepdim=True)
Tensor(shape=[2, 1], dtype=Float32, value=
[[ 1.00000000e+00],
[ 2.51661134e+00]])
>>> mindspore.mint.std(input, dim=[0, 1], correction=1, keepdim=False)
Tensor(shape=[], dtype=Float32, value= 1.75119)
>>> mindspore.mint.std(input, dim=[0, 1], correction=1, keepdim=True)
Tensor(shape=[1, 1], dtype=Float32, value=
[[ 1.75119019e+00]])
>>> mindspore.mint.std(input, dim=[0, 1], correction=2, keepdim=True)
Tensor(shape=[1, 1], dtype=Float32, value=
[[ 1.95789003e+00]])