PyTorch torch.absolute Function
PyTorch torch Reference Manual
torch.absoluteis a function in PyTorch for calculating element-wise absolute values, withtorch.absthe same functionality.
Function Definition
torch.absolute(input, out=None)
Usage Example
Example
import torch
# Create a tensor containing negative numbers
x = torch.tensor([-1.0, -2.0, 3.0, -4.0])
# Calculate the absolute value
result = torch.absolute(x)
print(result)
# Create a tensor containing negative numbers
x = torch.tensor([-1.0, -2.0, 3.0, -4.0])
# Calculate the absolute value
result = torch.absolute(x)
print(result)
The output is:
tensor([1., 2., 3., 4.])
Other Extensions