Python - PyTorch trunc() method Last Updated : 26 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report PyTorch torch.trunc() method returns a new tensor with the truncated integer values of the elements of input/ after removing the decimal portion of the number. Syntax: torch.trunc(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 the PyTorch library import torch # A constant tensor of size n a = torch.randn(6) print(a) # Applying the trunc function and # storing the result in 'out' out = torch.trunc(a) print(out) Output: 1.1257 0.4493 -0.7309 1.5523 -0.2877 0.1155 [torch.FloatTensor of size 6] 1 0 -0 1 -0 0 [torch.FloatTensor of size 6] Example 2: Python3 # Importing the PyTorch library import torch # A constant tensor of size n a = torch.FloatTensor([1.5, 3.9, -6.9, 3.678]) print(a) # Applying the trunc function and # storing the result in 'out' out = torch.trunc(a) print(out) Output: 1.5000 3.9000 -6.9000 3.6780 [torch.FloatTensor of size 4] 1 3 -6 3 [torch.FloatTensor of size 4] Comment More infoAdvertise with us Next Article Python - PyTorch log() method P PranchalKatiyar Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads Python | PyTorch tan() method PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes. The function torch.tan() provides support for the tangent function in PyTorch. It expects the input in radian form and the output is in the range [-â 2 min read Python - Pytorch randn() method PyTorch torch.randn() returns a tensor defined by the variable argument size (sequence of integers defining the shape of the output tensor), containing random numbers from standard normal distribution. Syntax: torch.randn(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad= 3 min read Python PyTorch zeros() method PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes. The function torch.zeros() returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size. Syntax: torch.zeros 1 min read Python PyTorch - rsqrt() method PyTorch rsqrt() method computes the reciprocal of the square root of each element of the input tensor. It accepts both real and complex-valued tensors. It returns 'NaN' (not a number) as the reciprocal of the square root of a negative number and 'inf' for zero. Mathematically, the below formula is u 3 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 abs() method 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' 1 min read Like