Pytorch Torch Std
# PyTorch torch.std Function
* * Pytorch torch Reference Manual](#)
`torch.std` is a function in PyTorch used to return the standard deviation of a tensor. Standard deviation is the square root of variance, measuring the dispersion of data.
### Function Definition
torch.std(input, dim, unbiased, keepdim=False)
* * *
## Usage Examples
## Example
import torch
x = torch.tensor([1.0,2.0,3.0,4.0,5.0])
# Return 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))
Output result:
Standard deviation: tensor(1.5811) dim=0 standard deviation: tensor([1.5000, 1.5000, 1.5000]) dim=1 standard deviation: tensor([1.0000, 1.0000])
* * Pytorch torch Reference Manual](#)
YouTip