Python – PyTorch abs() method Last Updated : 26 May, 2020 Improve Improve Like Article Like Save Share Report PyTorch torch.abs() method computes the element-wise absolute value of the given input tensor. Syntax: torch.abs(inp, out=None) ? Tensor Arguments inp: This is input tensor. out: This is optional parameter and is the output tensor. Return: It returns a Tensor having absolute value of input inp. Let’s see this concept with the help of few examples: Example 1: # Importing the PyTorch library import torch # A constant tensor of size 1 a = torch.FloatTensor([-15]) print(a) # Applying the abs function and # storing the result in 'b' b = torch.abs(a) print(b) Output: -15 [torch.FloatTensor of size 1] 15 [torch.FloatTensor of size 1] Example 2: # Importing the PyTorch library import torch # A constant tensor of size n a = torch.FloatTensor([15, -5, 3, -2]) print(a) # Applying the abs function and # storing the result in 'b' b = torch.abs(a) print(b) Output: 15 -5 3 -2 [torch.FloatTensor of size 4] 15 5 3 2 [torch.FloatTensor of size 4] Like Article Suggest improvement Next Python | PyTorch acos() method Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads PyTorch vs PyTorch Lightning abs() in Python Python | fabs() vs abs() Python | Pandas Series.abs() Python | Pandas DataFrame.abs() Python | Pandas Panel.abs() Python | PyTorch sin() method Python | PyTorch sinh() method Python | PyTorch cosh() method Python | PyTorch tanh() method Like P PranchalKatiyar Follow Article Tags : Python-PyTorch Python Practice Tags : python