mindspore.ops.var_mean
- mindspore.ops.var_mean(input, axis=None, ddof=0, keepdims=False)[source]
Returns the variance and mean of each row of the input Tensor by default, or it can calculate them in specified dimension axis. If axis is a list of dimensions, reduce over all of them.
Note
If ddof is 0, 1, True or False, the supported device is only Ascend and CPU. In other cases, the supported device is Ascend, GPU and CPU.
- Parameters
input (Tensor[Number]) – Input Tensor with a dtype of number.Number, its shape should be \((N, *)\) where \(*\) means any number of additional dims.
axis (Union[int, tuple(int)], optional) – The dimensions to reduce. Only constant value is allowed. Must be in the range [-rank(input), rank(input)). Default:
None
, reduce all dimensions.ddof (Union[int, bool], optional) – Means Delta Degrees of Freedom. If ddof is an integer, the divisor used in calculations is \(N - ddof\), where \(N\) represents the number of elements. If ddof is True, will use the Bessel correction unbiased estimation. If ddof is False, will through the biased estimation to calculate the variance. Default:
0
.keepdims (bool, optional) – Whether the output Tensor has dim retained or not. If true, keep these reduced dimensions and the length is 1. If false, don’t keep these dimensions. Default:
False
.
- Returns
A tuple containing the variance and mean. Suppose the shape of input is \((x_0, x_1, ..., x_R)\):
If axis is () and keepdims is set to
False
, returns a 0-D Tensor, indicating the standard deviation of all elements in input.If axis is int 1 and keepdims is set to
False
, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).If axis is tuple(int) or list(int), e.g. (1, 2) and keepdims is set to
False
, then the returned Tensor has shape \((x_0, x_2, ..., x_R)\).
- Raises
TypeError – If input is not a Tensor.
TypeError – If axis is not one of the following: None, int, tuple.
TypeError – If keepdims is not a bool.
ValueError – If axis is out of range.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore as ms >>> input = ms.Tensor([[1, 2, 3, 4], [-1, 1, 4, -10]], ms.float32) >>> output_var, output_mean = ms.ops.var_mean(input, 1, 2, True) >>> print(output_var) [[ 2.5] [54.5]] >>> print(output_mean) [[ 2.5] [-1.5]]