mindspore.mint.var_mean
- mindspore.mint.var_mean(input, dim=None, *, correction=1, keepdim=False)[source]
Compute the variance and the mean of the tensor along a specified dimension.
The variance (\(\sigma ^2\)) is calculated as:
\[\sigma ^2 = \frac{1}{N - \delta N} \sum_{j=0}^{N-1} \left(self_{ij} - \overline{x_{i}}\right)^{2}\]where is \(x\) the sample set of elements, \(\bar{x}\) is the sample mean, \(N\) is the number of samples and \(\delta N\) is the correction .
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
- Keyword Arguments
- Returns
Tuple(var, mean) of 2 tensors.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> input = mindspore.tensor([[1, 3, 4, 2], [4, 2, 5, 3], [5, 4, 2, 3]], mindspore.float32) >>> output = mindspore.mint.var_mean(input, 0, correction=1) >>> print(output) (Tensor(shape=[4], dtype=Float32, value= [ 4.33333302e+00, 1.00000000e+00, 2.33333349e+00, 3.33333313e-01]), Tensor(shape=[4], dtype=Float32, value= [ 3.33333349e+00, 3.00000000e+00, 3.66666675e+00, 2.66666675e+00])) >>> output = mindspore.mint.var_mean(input, 1, correction=2, keepdim=True) >>> print(output) (Tensor(shape=[3, 1], dtype=Float32, value= [[ 2.50000000e+00], [ 2.50000000e+00], [ 2.50000000e+00]]), Tensor(shape=[3, 1], dtype=Float32, value= [[ 2.50000000e+00], [ 3.50000000e+00], [ 3.50000000e+00]]))