PyTorch torch.aminmax function
PyTorch torch reference manual
torch.aminmax is a function in PyTorch used to return the minimum and maximum values of a tensor.
Function definition
torch.aminmax(input, dim=None, keepdim=False)
Usage examples
Example
import
torch
x
=
torch.
tensor
(
[
[
1
,
3
,
2
]
,
[
4
,
1
,
3
]
]
)
Return the minimum and maximum of all elements
mm
=
torch.
aminmax
(
x
)
(
"Minimum:"
,
mm
[
0
]
)
(
"Maximum:"
,
mm
[
1
]
)
Minimum and maximum along dim=0
mm0
=
torch.
aminmax
(
x
,
dim
=
0
)
(
"dim=0 minimum:"
,
mm0
[
0
]
)
(
"dim=0 maximum:"
,
mm0
[
1
]
)
Minimum and maximum along dim=1
mm1
=
torch.
aminmax
(
x
,
dim
=
1
)
(
"dim=1 minimum:"
,
mm1
[
0
]
)
(
"dim=1 maximum:"
,
mm1
[
1
]
)
The output is:
最小值: tensor(1)
最大值: tensor(4)
dim=0 最小值: tensor([1, 1, 2])
dim=0 最大值: tensor([4, 3, 3])
dim=1 最小值: tensor([1, 1])
dim=1 最大值: tensor([3, 4])