PyTorch torch.std Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.stdis a function in PyTorch used to return the standard deviation of a tensor. The standard deviation is the square root of the variance and measures the dispersion of the data.

Function Definition

torch.std(input, dim, unbiased, keepdim=False)

Usage Example

Example

import torch

x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0])

# Return the standard deviation of all elements
print("Standard deviation:", torch.std(x))

# Standard deviation along dim=0
y = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
print("dim=0 standard deviation:", torch.std(y, dim=0))
print("dim=1 standard deviation:", torch.std(y, dim=1))

The output result is:

标准差: tensor(1.5811)
dim=0 标准差: tensor([1.5000, 1.5000, 1.5000])
dim=1 标准差: tensor([1.0000, 1.0000])

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions