fn

std

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

Compute the sample standard deviation along dim.

Defined as the square root of the (corrected) sample variance. The correction keyword selects between Bessel-corrected (correction=1, the default — divides by n1n-1) and biased (correction=0 — divides by nn) estimates.

Parameters

xTensor
Input tensor.
dimint or list of int= None
Dimension(s) to reduce.
keepdimbool= False
Whether to retain reduced dims with size 1.
correctionint= 1
Degrees-of-freedom correction. 1 for unbiased, 0 for biased.

Returns

Tensor

Reduced floating-point tensor.

Notes

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

where cc is the correction and xˉ\bar{x} is the sample mean.

Examples

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