PyTorch torch.abs Function
Pytorch torch Reference Manual
torch.absIt is a function in PyTorch used to calculate the absolute value of tensors.
Function Definition
torch.abs(input, out=None)
Usage Example
Example
import torch
# Create a tensor containing negative numbers
x = torch.tensor([-1, -2, 3, -4])
# Compute absolute values
y = torch.abs(x)
print(y)
# Create a tensor containing negative numbers
x = torch.tensor([-1, -2, 3, -4])
# Compute absolute values
y = torch.abs(x)
print(y)
The output result is:
tensor([1, 2, 3, 4])
Other Extensions