- torch.std(input, dim=None, *, correction=1, keepdim=False, out=None) Tensor ¶
Calculates the standard deviation over the dimensions specified by
dimcan be a single dimension, list of dimensions, or
Noneto reduce over all dimensions.
The standard deviation () is calculated as
where is the sample set of elements, is the sample mean, is the number of samples and is the
True, the output tensor is of the same size as
inputexcept in the dimension(s)
dimwhere it is of size 1. Otherwise,
dimis squeezed (see
torch.squeeze()), resulting in the output tensor having 1 (or
len(dim)) fewer dimension(s).
- Keyword Arguments:
correction (int) –
difference between the sample size and sample degrees of freedom. Defaults to Bessel’s correction,
Changed in version 2.0: Previously this argument was called
unbiasedand was a boolean with
keepdim (bool) – whether the output tensor has
dimretained or not.
out (Tensor, optional) – the output tensor.
>>> a = torch.tensor( ... [[ 0.2035, 1.2959, 1.8101, -0.4644], ... [ 1.5027, -0.3270, 0.5905, 0.6538], ... [-1.5745, 1.3330, -0.5596, -0.6548], ... [ 0.1264, -0.5080, 1.6420, 0.1992]]) >>> torch.std(a, dim=1, keepdim=True) tensor([[1.0311], [0.7477], [1.2204], [0.9087]])