std(inp, axis=None, keepdims=False)[源代码]

Calculates the standard deviation of tensor elements over a given axis (or axes).

  • inp (Tensor) – input tensor. Should have a numeric data type.

  • axis (Union[int, Sequence[int], None]) – axis or axes along which standard deviations must be computed. By default, the standard deviation must be computed over the entire tensor. If a sequence of integers, standard deviations must be computed over multiple axes.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input tensor (see 广播机制与规则). Otherwise, if False, the reduced axes (dimensions) must not be included in the result.




if the standard deviation was computed over the entire tensor, a zero-dimensional tensor containing the standard deviation; otherwise, a non-zero-dimensional tensor containing the standard deviations.


The standard deviation is the square root of the average of the squared deviations from the mean, i.e., std = sqrt(mean(x)), where x = abs(a - a.mean())**2.


>>> x = Tensor([[1, 2], [3, 4]])
>>> F.std(x)
Tensor(1.118034, device=xpux:0)
>>> x = Tensor([[14, 8, 11, 10], [7, 9, 10, 11], [10, 15, 5, 10]])
>>> F.std(x)
Tensor(2.6140645, device=xpux:0)