Python PyTorch zeros() method Last Updated : 22 Apr, 2020 Comments Improve Suggest changes Like Article Like Report 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(size, out=None) Parameters: size: a sequence of integers defining the shape of the output tensor out (Tensor, optional): the output tensor Return type: A tensor filled with scalar value 0, of same shape as size. Code #1: Python3 # Importing the PyTorch library import torch # Applying the zeros function and # storing the resulting tensor in 't' a = torch.zeros([3, 4]) print("a = ", a) b = torch.zeros([1, 5]) print("b = ", b) c = torch.zeros([5, 1]) print("c = ", c) d = torch.zeros([3, 3, 2]) print("d = ", d) Output: a = tensor([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]) b = tensor([[0., 0., 0., 0., 0.]]) c = tensor([[0.], [0.], [0.], [0.], [0.]]) d = tensor([[[0., 0.], [0., 0.], [0., 0.]], [[0., 0.], [0., 0.], [0., 0.]], [[0., 0.], [0., 0.], [0., 0.]]]) Comment More infoAdvertise with us Next Article Python - PyTorch floor() method S sanskar27jain Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads Python | sympy.zeros() method With the help of sympy.zeros() method, we can create a matrix having dimension nxm and filled with zeros by using sympy.zeros() method.Syntax : sympy.zeros()Return : Return a zero matrix.Example #1 :In this example, we can see that by using sympy.zero() method, we are able to create the zero matrix 1 min read Python | sympy.zeros() method With the help of sympy.zeros() method, we can create a matrix having dimension nxm and filled with zeros by using sympy.zeros() method.Syntax : sympy.zeros()Return : Return a zero matrix.Example #1 :In this example, we can see that by using sympy.zero() method, we are able to create the zero matrix 1 min read Python | sympy.zeros() method With the help of sympy.zeros() method, we can create a matrix having dimension nxm and filled with zeros by using sympy.zeros() method.Syntax : sympy.zeros()Return : Return a zero matrix.Example #1 :In this example, we can see that by using sympy.zero() method, we are able to create the zero matrix 1 min read Python - PyTorch trunc() method 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 t 1 min read Python - PyTorch floor() method PyTorch torch.floor() method returns a new tensor which is floor of the elements of input, the largest integer less than or equal to each element. Syntax: torch.floor(input, out=None) Arguments input: This is input tensor. out: The output tensor. Return: It returns a Tensor. Let's see this concept w 1 min read Python | Decimal is_zero() method Decimal#is_zero() : is_zero() is a Decimal class method which checks whether the Decimal value is zero value. Syntax: Decimal.is_zero() Parameter: Decimal values Return: true - if the Decimal value is zero value; otherwise false Code #1 : Example for is_zero() method Python3 # Python Program explain 2 min read Like