PyTorch torch.max function
PyTorch torch reference manual
torch.max is a function in PyTorch used to compute the maximum value of a tensor.
Function definition
torch.max(input, dim, keepdim, out)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
[
1
,
2
,
3
]
,
[
4
,
5
,
6
]
]
)
global maximum
(
"Global maximum:"
,
torch.
max
(
x
)
)
Maximum along a dimension
(
"dim=0 maximum:"
,
torch.
max
(
x
,
dim
=
0
)
)
The output is:
全局最大: tensor(6)
dim=0 最大: torch.return_types.max(values=tensor([4, 5, 6]), indices=tensor([1, 1, 1]))