PyTorch torch.mean function
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
(
"Global mean:"
,
torch.
mean
(
x
)
)
Compute the mean along dim=0
(
"dim=0 mean:"
,
torch.
mean
(
x
,
dim
=
0
)
)
The output is:
全局均值: tensor(3.5000)
dim=0 均值: tensor([2.5000, 3.5000, 4.5000])