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

PyTorch torch.mean function

PyTorch torch.mean function


PyTorch torch reference manual PyTorch torch reference manual

torch.mean is a function in PyTorch used to compute the mean of a tensor.

Function definition

torch.mean(input, dim, keepdim, dtype, out)


Usage examples

Example

import

torch

x

=

torch.

tensor

(

[

[

1

,

2

,

3

]

,

[

4

,

5

,

6

]

]

)

Compute the mean of all elements

print

(

"Global mean:"

,

torch.

mean

(

x

)

)

Compute the mean along dim=0

print

(

"dim=0 mean:"

,

torch.

mean

(

x

,

dim

=

0

)

)

The output is:

全局均值: tensor(3.5000)

dim=0 均值: tensor([2.5000, 3.5000, 4.5000])


PyTorch torch reference manual PyTorch torch reference manual