mindspore.ops.std
- mindspore.ops.std(input, axis=None, ddof=0, keepdims=False)[源代码]
计算Tensor在指定轴上的标准差。
- 参数:
input (Tensor[Number]) - 输入Tensor。
axis (Union[int, tuple(int)],可选) - 指定计算轴。如果为
None
,计算 input 中的所有元素。默认None
。ddof (Union[int, bool],可选) - δ自由度。默认
0
。如果为整数,计算中使用的除数是
,其中 表示元素的数量。如果为bool值,
True
与False
分别对应ddof为整数时的1
与0
。如果取值为0、1、True或False,支持的平台只有 Ascend 和 CPU 。其他情况下,支持平台是 Ascend 、 GPU 和 CPU 。
keepdims (bool,可选) - 输出Tensor是否保留维度。默认
False
。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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]]