Python - PyTorch numel() method Last Updated : 26 May, 2020 Comments Improve Suggest changes Like Article Like Report PyTorch torch.numel() method returns the total number of elements in the input tensor. Syntax: torch.numel(input) Arguments input: This is input tensor. Return: It returns the length of the input 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(4, 6) print(a) # Applying the numel function and # storing the result in 'out' out = torch.numel(a) print(out) Output: -0.8263 0.9807 -1.4688 0.2117 -0.8356 -0.0228 -0.8815 1.3652 -0.1892 -1.1241 0.2755 1.3006 0.0559 0.2389 0.7944 2.6587 -2.0908 1.2973 -0.2056 0.4110 0.2163 0.3091 0.5559 -0.2468 [torch.FloatTensor of size 4x6] 24 Example 2: Python3 # Importing the PyTorch library import torch # A constant tensor of size n a = torch.FloatTensor([1, 4, 6, 8]) print(a) # Applying the numel function and # storing the result in 'out' out = torch.numel(a) print(out) Output: 1 4 6 8 [torch.FloatTensor of size 4] 4 Comment More infoAdvertise with us Next Article Python - PyTorch numel() method P PranchalKatiyar Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads Python Pytorch ones() 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.ones() returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size. Syntax: torch.ones(s 1 min read Python | PyTorch sin() 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.sin() provides support for the sine function in PyTorch. It expects the input in radian form and the output is in the range [-1, 1 2 min read 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 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 add() method 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 1 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 cos() 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.cos() provides support for the cosine function in PyTorch. It expects the input in radian form and the output is in the range [-1, 2 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 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 Python | PyTorch sinh() 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.sinh() provides support for the hyperbolic sine function in PyTorch. It expects the input in radian form. The input type is tensor 2 min read Like