PyTorch torch.amax function
PyTorch torch reference manual
torch.amax is a function in PyTorch used to return the maximum value of a tensor along a specified dimension.
Function definition
torch.amax(input, dim, keepdim=False)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
[
1
,
3
,
2
]
,
[
4
,
1
,
3
]
]
)
Return the maximum of all elements
(
"Global maximum:"
,
torch.
amax
(
x
)
)
Maximum along dim=0
(
"dim=0 maximum:"
,
torch.
amax
(
x
,
dim
=
0
)
)
Maximum along dim=1
(
"dim=1 maximum:"
,
torch.
amax
(
x
,
dim
=
1
)
)
The output is:
全局最大: tensor(4)
dim=0 最大: tensor([4, 3, 3])
dim=1 最大: tensor([3, 4])