mindspore.mint.var_mean
- mindspore.mint.var_mean(input, dim=None, *, correction=1, keepdim=False)[source]
By default, return the variance and mean of each dimension in Tensor. If dim is a dimension list, calculate the variance and mean of the corresponding dimension.
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) – Difference between the sample size and sample degrees of freedom. Defaults to Bessel's correction. Default:
1
.keepdim (bool, optional) – Whether to preserve the dimensions of the output Tensor. If True, retain the reduced dimension with a size of 1. Otherwise, remove the dimensions. Default value:
False
.
- Returns
A tuple of variance and mean.
- Raises
TypeError – If input is not a Tensor.
TypeError – If dim is not one of the following data types: int, tuple, list, or Tensor.
TypeError – If keepdim is not a bool.
ValueError – If dim is out of range.
- Supported Platforms:
Ascend
Examples
>>> import mindspore as ms >>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32) >>> output_var, output_mean = ms.mint.var_mean(input, 1, correction=2, keepdim=True) >>> print(output_var) [[ 2.5] [54.5]] >>> print(output_mean) [[ 2.5] [-1.5]]