giagrad.Tensor.std#
- Tensor.std(axis=None, ddof=1, keepdims=False, eps=0.0)[source]#
Calculates the standard deviation over the axis specified by
axis.The standard deviation (\(\sigma\)) is calculated as:
\[\sigma = \sqrt{\frac{1}{N-\text{ddof}}\sum_{i=0}^{N-1}(x_i-\bar{x})^2 + \epsilon}\]If keepdims is
True, the output tensor is of the same size as input except in theaxiswhere it is of size 1. Otherwise, everyaxisis squeezed, leading to an output tensor with fewer dimensions. If noaxisis supplied all data is reduced to a scalar value. Optional parameterepscould be used for numerical stability.- Parameters:
axis¶ ((int, ...) or int or None, default: None) – The dimension or dimension to reduce. If None, std reduces all dimensions.
ddof¶ (int, default: 1) – Degrees of freedom substracted to N.
ddof=1equals sample variance,ddof=0equals population variance.keepdims¶ (bool, default: False) – Whether te output tensor should retain the reduced dimensions.
eps¶ (float, default: 0.0) – Epsilon value added to \(\mathrm{Var}[x]\) for numerical stability.
Examples
>>> a = Tensor.empty(2, 2, 3, dtype=int).uniform(0, 10) >>> a tensor: [[[2 8 5] [8 4 6]] ... [[7 9 6] [3 3 6]]] >>> a.std() tensor: 2.1392496 fn: Pow >>> a.std((0, 1), keepdims=True, ddof=1) tensor: [[[2.94392029 2.94392029 0.5 ]]] fn: Pow >>> a.std((0, 1), keepdims=True, ddof=1).ndim 3 >>> a.std((0, 1), keepdims=True, ddof=1, eps=.1) tensor: [[[2.96085573 2.96085573 0.59160798]]] fn: Pow >>> (a.var((0, 1), keepdims=True, ddof=1) + .1).sqrt() tensor: [[[2.96085573 2.96085573 0.59160798]]] fn: Pow