PyTorch torch.abs Function


Pytorch torch 参考手册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)

The output result is:

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

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions