Returns the variance of each row of the input tensor in the given dimension dim.

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 flow.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).

  • input (Tensor) – the input tensor.

  • dim (int or tuple of ints) – the dimension or dimensions to reduce. Defaults to None.

  • unbiased (bool, optional) – whether to use Bessel’s correction (\(\delta N = 1\)). Defaults to True.

  • keepdim (bool, optional) – whether the output tensor has dim retained or not. Defaults to False.


The result of variance on the specified axis of input Tensor

Return type


For example:

>>> import numpy as np
>>> import oneflow as flow

>>> input = flow.tensor(np.random.randn(2, 3, 4, 5))
>>> output = flow.var(input, 1, True)