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

PyTorch torch.absolute Function

PyTorch torch.absolute Function


PyTorch torch reference manual PyTorch torch reference manual

torch.absolute is a function in PyTorch used to compute the element-wise absolute value, the same as torch.abs in functionality.

Function definition



torch.absolute(input, out=None)


Usage examples

Example

import

torch

Create a tensor containing negative numbers

x

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

,

4.0

]

)

Compute the absolute value

result

=

torch.

absolute

(

x

)

print

(

result

)

The output is:



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


PyTorch torch reference manual PyTorch torch reference manual