torch.var
- torch.var(input, dim=None, *, correction=1, keepdim=False, out=None) →
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.
If keepdim is True, the output tensor is of the same size
as input except in the dimension(s) dim where it is of size 1.
Otherwise, dim is squeezed (see torch.squeeze()), resulting in the
output tensor having 1 (or len(dim)) fewer dimension(s).
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction, .
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330
correction=1keepdim (bool, optional) – whether the output tensor has dim retained or not. Default: False.
out (Tensor, optional) – the output tensor.