PyTorch torch.argmax function
PyTorch torch reference manual
torch.argmax is a function in PyTorch used to return the index of the maximum value along a dimension.
Function definition
torch.argmax(input, dim, keepdim)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
[
1
,
3
,
2
]
,
[
4
,
1
,
3
]
]
)
Index of the global maximum
(
"Global maximum index:"
,
torch.
argmax
(
x
)
)
Index of the maximum along dim=0
(
"dim=0 maximum index:"
,
torch.
argmax
(
x
,
dim
=
0
)
)
Index of the maximum along dim=1
(
"dim=1 maximum index:"
,
torch.
argmax
(
x
,
dim
=
1
)
)
The output is:
全局最大索引: tensor(4)
dim=0 最大索引: tensor([1, 0, 1])
dim=1 最大索引: tensor([1, 0])