mindspore.numpy.var
- mindspore.numpy.var(x, axis=None, ddof=0, keepdims=False)[源代码]
Computes the variance along the specified axis. The variance is the average of the squared deviations from the mean, i.e., \(var = mean(abs(x - x.mean())**2)\).
Returns the variance, which is computed for the flattened array by default, otherwise over the specified axis.
说明
Numpy arguments dtype, out and where are not supported.
- 参数
x (Tensor) – A Tensor to be calculated.
axis (Union[None, int, tuple(int)]) – Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array. Default: None.
ddof (int) – Means Delta Degrees of Freedom. Default: 0. The divisor used in calculations is \(N - ddof\), where \(N\) represents the number of elements.
keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input tensor. If the default value is passed, then keepdims will not be passed through to the var method of sub-classes of tensor, however any non-default value will be. If the sub-class method does not implement keepdims any exceptions will be raised. Default: False.
- Supported Platforms:
Ascend
GPU
CPU
- 返回
Standard deviation tensor.
样例
>>> import mindspore.numpy as np >>> input_x = np.array([1., 2., 3., 4.]) >>> output = np.var(input_x) >>> print(output) 1.25