Skip to content
fn

std

→Tensor
std(input: Tensor, dim: _int | Sequence[_int] | None = None, unbiased: _bool | None = None, keepdim: _bool = False, correction: _int | _float | None = None)

Implementing kernel

C++ engine symbols that back this Python API.

Compute the standard deviation along dim.

The square root of var with the same arguments: correction=1 (the default) divides by n−1n-1, correction=0 by nn.

Parameters

inputTensor
Input tensor.
dimint or sequence of int= None
Dimension(s) to reduce. None reduces every element. A dimension named twice is refused.
unbiasedbool= None
True is correction=1, False correction=0; it overrides correction when given. A bool in the place of dim — std(x, False) — is read as this.
keepdimbool= False
Whether to retain reduced dims with size 1.
correctionint or float= None
Degrees-of-freedom correction. Default 1.

Returns

Tensor

Reduced floating-point tensor.

Raises

ValueError
If dim names one dimension twice.

Notes

σ  =  1max⁡(n−c,0)∑i=1n(xi−xˉ)2.\sigma \;=\; \sqrt{ \frac{1}{\max(n - c, 0)} \sum_{i=1}^{n} (x_i - \bar{x})^2 } .

The gradient of a slice with no spread (std 0) is 0, the subgradient the reference picks, rather than nan. Too few elements (n≤cn \le c) give nan or inf, as var explains.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0, 4.0])
>>> lucid.std(x)
tensor(1.291)
>>> lucid.std(x, correction=0)
tensor(1.118)