mindspore.ops.std
- mindspore.ops.std(input, axis=None, ddof=0, keepdims=False)[source]
Compute the standard deviation of the tensor along a specified axis.
- Parameters
input (Tensor[Number]) – The input tensor.
axis (Union[int, tuple(int)], optional) – Specify the axis for computation. If
None, compute all elements in the input . DefaultNone.ddof (Union[int, bool], optional) –
Means Delta Degrees of Freedom. Default
0.If ddof is an integer, the divisor used in calculations is \(N - ddof\), where \(N\) represents the number of elements.
If ddof is a boolean,
TrueandFalsecorrespond to when ddof is an integer1and0respectively.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.
keepdims (bool, optional) – Whether the output tensor has dim retained. Default
False.
- Returns
Tensor
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[1., 3, 4, 2], ... [4, 2, 5, 3], ... [5, 4, 2, 3]]) >>> # case 1: By default, compute the standard deviation of all elements. >>> output = mindspore.ops.std(input) >>> print(output) 1.2133516 >>> >>> # case 2: Compute the standard deviation along axis 0. >>> output = mindspore.ops.std(input, axis=0) >>> print(output) [1.6996732 0.8164966 1.2472192 0.4714045] >>> >>> # case 3: If keepdims=True, the output shape will be same of that of the input. >>> output = mindspore.ops.std(input, axis=0, keepdims=True) >>> print(output) [[1.6996732 0.8164966 1.2472192 0.4714045]] >>> >>> # case 4: If ddof=1: >>> output = mindspore.ops.std(input, axis=0, keepdims=True, ddof=1) >>> print(output) [[2.081666 1. 1.5275253 0.57735026]] >>> >>> # case 5: If ddof=True, same as ddof=1: >>> output = mindspore.ops.std(input, axis=0, keepdims=True, ddof=True) >>> print(output) [[2.081666 1. 1.5275253 0.57735026]] >>> >>> # case 6: If ddof=False, same as ddof=0: >>> output = mindspore.ops.std(input, axis=0, keepdims=True, ddof=False) >>> print(output) [[1.6996732 0.8164966 1.2472192 0.4714045]]