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

PyTorch torch.abs Function

PyTorch torch.abs Function


PyTorch torch reference manual PyTorch torch reference manual

torch.abs is a function in PyTorch used to compute the absolute value of a tensor.

Function definition



torch.abs(input, out=None)


Usage examples

Example

import

torch

Create a tensor containing negative numbers

x

=

torch.

tensor

(

[

1

,

2

,

3

,

4

]

)

Compute the absolute value

y

=

torch.

abs

(

x

)

print

(

y

)

The output is:



tensor([1, 2, 3, 4])


PyTorch torch reference manual PyTorch torch reference manual