Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.std function

PyTorch torch.std function


PyTorch torch reference manual PyTorch torch reference manual

torch.std is 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 examples

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 is:

标准差: tensor(1.5811)

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

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


PyTorch torch reference manual PyTorch torch reference manual