fn

var

Tensor
var(x: Tensor, dim: _int | list[_int] | None = None, keepdim: _bool = False, correction: _int = 1)
source

Compute the sample variance along dim.

Computes the mean squared deviation from the per-slice mean. Selecting correction=1 (default) yields Bessel's unbiased estimator; correction=0 produces the maximum-likelihood (biased) estimator.

Parameters

xTensor
Input tensor.
dimint or list of int= None
Dimension(s) to reduce.
keepdimbool= False
Retain reduced dims with size 1.
correctionint= 1
Degrees-of-freedom correction.

Returns

Tensor

Reduced floating-point tensor.

Notes

Var(x)  =  1nci=1n(xixˉ)2,\mathrm{Var}(x) \;=\; \frac{1}{n - c} \sum_{i=1}^{n} (x_i - \bar{x})^2 ,

with c{0,1}c \in \{0, 1\} set by the correction keyword.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0, 4.0])
>>> lucid.var(x)
Tensor(1.6667)