var
- paddle. var ( x: Tensor, axis: int | Sequence[int] | None = None, unbiased: bool | None = None, keepdim: bool = False, name: str | None = None, *, correction: float = 1, out: Tensor | None = None ) Tensor [source]
-
Computes the variance of
x
alongaxis
.Note
Alias Support: The parameter name
input
can be used as an alias forx
, anddim
can be used as an alias foraxis
. For example,var(input=tensor_x, dim=1, ...)
is equivalent tovar(x=tensor_x, axis=1, ...)
.- Parameters
-
x (Tensor) – The input Tensor with data type float16, float32, float64. alias:
input
.axis (int|list|tuple|None, optional) –
The axis along which to perform variance calculations.
axis
should be int, list(int) or tuple(int). alias:dim
.If
axis
is a list/tuple of dimension(s), variance is calculated along all element(s) ofaxis
.axis
or element(s) ofaxis
should be in range [-D, D), where D is the dimensions ofx
.If
axis
or element(s) ofaxis
is less than 0, it works the same way as \(axis + D\) .If
axis
is None, variance is calculated over all elements ofx
. 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 alongaxis
, 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|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.
correction (int|float, optional) – Difference between the sample size and sample degrees of freedom. Defaults to 1 (Bessel’s correction). If unbiased is specified, this parameter is ignored.
out (Tensor|None, optional) – Output tensor. Default is None.
- Returns
-
Tensor, results of variance along
axis
ofx
, with the same data type asx
.
Examples
>>> import paddle >>> x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]]) >>> out1 = paddle.var(x) >>> print(out1.numpy()) 2.6666667 >>> out2 = paddle.var(x, axis=1) >>> print(out2.numpy()) [1. 4.3333335]