mindspore.Tensor.var
- Tensor.var(axis=None, ddof=0, keepdims=False)[source]
Compute the variance along the specified axis.
The variance is the average of the squared deviations from the mean, i.e.,
.Return the variance, which is computed for the flattened array by default, otherwise over the specified axis.
Note
Numpy arguments dtype, out and where are not supported.
- Parameters
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 , where represents the number of elements.keepdims (bool) – Default:
False
.
- Returns
Variance tensor.
See also
mindspore.Tensor.mean()
: Reduce a dimension of a tensor by averaging all elements in the dimension.mindspore.Tensor.std()
: Compute the standard deviation along the specified axis.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> input_x = Tensor(np.array([1., 2., 3., 4.], np.float32)) >>> output = input_x.var() >>> print(output) 1.25