Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.amax function

PyTorch torch.amax function


PyTorch torch reference manual 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

print

(

"Global maximum:"

,

torch.

amax

(

x

)

)

Maximum along dim=0

print

(

"dim=0 maximum:"

,

torch.

amax

(

x

,

dim

=

0

)

)

Maximum along dim=1

print

(

"dim=1 maximum:"

,

torch.

amax

(

x

,

dim

=

1

)

)

The output is:

全局最大: tensor(4)

dim=0 最大: tensor([4, 3, 3])

dim=1 最大: tensor([3, 4])


PyTorch torch reference manual PyTorch torch reference manual