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

PyTorch torch.maximum function

PyTorch torch.maximum function


PyTorch torch reference manual PyTorch torch reference manual

torch.maximum is a function in PyTorch used to take the element-wise maximum. It returns a new tensor made of the maximum of corresponding elements of two tensors.

Function definition

torch.maximum(input, other)


Usage examples

Example

import

torch

Create two tensors

x

=

torch.

tensor

(

[

3

,

1

,

4

]

)

y

=

torch.

tensor

(

[

1

,

5

,

2

]

)

Element-wise maximum

result

=

torch.

maximum

(

x

,

y

)

print

(

result

)

The output is:

tensor([3, 5, 4])


PyTorch torch reference manual PyTorch torch reference manual