Python - PyTorch add() method Last Updated : 26 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report PyTorch torch.add() method adds a constant value to each element of the input tensor and returns a new modified tensor. Syntax: torch.add(inp, c, out=None) Arguments inp: This is input tensor. c: The value that is to be added to every element of tensor. out: This is optional parameter and it is the output tensor. Return: It returns a Tensor. Let's see this concept with the help of few examples: Example 1: Python3 # Importing the PyTorch library import torch # A constant tensor of size 6 a = torch.randn(6) print(a) # Applying the add function and # storing the result in 'b' b = torch.add(a, 5) print(b) Output: 0.2403 1.3826 -0.1763 -1.5177 -0.0555 1.4558 [torch.FloatTensor of size 6] 5.2403 6.3826 4.8237 3.4823 4.9445 6.4558 [torch.FloatTensor of size 6] Example 2: Python3 # Importing the PyTorch library import torch # A constant tensor of size 6 a = torch.FloatTensor([1, 3, 8, 4, 10]) print(a) # Applying the add function and # storing the result in 'b' b = torch.add(a, 5) print(b) Output: 1 3 8 4 10 [torch.FloatTensor of size 5] 6 8 13 9 15 [torch.FloatTensor of size 5] Comment More infoAdvertise with us Next Article Python - PyTorch add() method P PranchalKatiyar Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads Python - PyTorch div() method PyTorch torch.div() method divides every element of the input with a constant and returns a new modified tensor. Syntax: torch.div(inp, other, out=None) Arguments inp: This is input tensor. other: This is a number to be divided to each element of input inp. out: The output tensor. Return: It returns 1 min read Python - PyTorch frac() method PyTorch torch.frac() method computes the fractional portion of each element in input. Syntax: torch.frac(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see this concept with the help of few examples: Example 1: Python3 # Importing t 1 min read Python - PyTorch clamp() method PyTorch torch.clamp() method clamps all the input elements into the range [ min, max ] and return a resulting tensor. Syntax: torch.clamp(inp, min, max, out=None) Arguments inp: This is input tensor. min: This is a number and specifies the lower-bound of the range to which input to be clamped. max: 2 min read Python - PyTorch log() method PyTorch torch.log() method gives a new tensor having the natural logarithm of the elements of input tensor. Syntax: torch.log(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see this concept with the help of few examples: Example 1: 1 min read Python - PyTorch exp() method PyTorch torch.exp() method returns a new tensor after getting the exponent of the elements of the input tensor. Syntax: torch.exp(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see this concept with the help of few examples: Example 1 min read Like