paddle. var ( x, axis=None, unbiased=True, keepdim=False, name=None ) [source]

Computes the variance of x along axis .

  • x (Tensor) – The input Tensor with data type float32, float64.

  • axis (int|list|tuple, optional) –

    The axis along which to perform variance calculations. axis should be int, list(int) or tuple(int).

    • If axis is a list/tuple of dimension(s), variance is calculated along all element(s) of axis . axis or element(s) of axis should be in range [-D, D), where D is the dimensions of x .

    • If axis or element(s) of axis is less than 0, it works the same way as \(axis + D\) .

    • If axis is None, variance is calculated over all elements of x. Default is None.

  • unbiased (bool, optional) – Whether to use the unbiased estimation. If unbiased is True, the divisor used in the computation is \(N - 1\), where \(N\) represents the number of elements along axis , otherwise the divisor is \(N\). Default is True.

  • keep_dim (bool, optional) – Whether to reserve the reduced dimension in the output Tensor. The result tensor will have one fewer dimension than the input unless keep_dim is true. Default is False.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


Tensor, results of variance along axis of x, with the same data type as x.


import paddle

x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]])
out1 = paddle.var(x)
# [2.66666667]
out2 = paddle.var(x, axis=1)
# [1.         4.33333333]