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

PyTorch torch.max function

PyTorch torch.max function


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

print

(

"Global maximum:"

,

torch.

max

(

x

)

)

Maximum along a dimension

print

(

"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]))


PyTorch torch reference manual PyTorch torch reference manual