PyTorch torch.abs Function
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
)
(
y
)
The output is:
tensor([1, 2, 3, 4])