mindspore.mint.var
- mindspore.mint.var(input, dim=None, *, correction=1, keepdim=False)[source]
Calculates the variance over the dimensions specified by dim. dim can be a single dimension, list of dimensions, or None to reduce over all dimensions.
The variance (
) is calculated as:where
is the sample set of elements, is the sample mean, is the number of samples and is the correction.Warning
This is an experimental API that is subject to change or deletion.
- Parameters
- Keyword Arguments
correction (int, optional) – The difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction. Defaults to
1
.keepdim (bool, optional) – Whether the output tensor has dim retained or not. If
True
, keep these reduced dimensions and the length is 1. IfFalse
, don't keep these dimensions. Defaults toFalse
.
- Returns
Tensor, the variance. Suppose the shape of input is
:If dim is () and keepdim is set to
False
, returns a 0-D Tensor, indicating the variance of all elements in input.If dim is int, e.g.
1
and keepdim is set toFalse
, then the returned Tensor has shape .If dim is tuple(int) or list(int), e.g.
(1, 2)
and keepdim is set toFalse
, then the returned Tensor has shape .
- Raises
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> from mindspore import Tensor, mint >>> input = Tensor([[8, 2, 1], [5, 9, 3], [4, 6, 7]], mindspore.float32) >>> output = mint.var(input, dim=0, correction=1, keepdim=True) >>> print(output) [[ 4.333333, 12.333333, 9.333333]]