Python Pytorch empty() 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.empty() returns a tensor filled with uninitialized data. The shape of the tensor is defined by the variable argument size. Syntax: torch.empty(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 Code #1: Python3 # Importing the PyTorch library import torch # Applying the empty function and # storing the resulting tensor in 'a' a = torch.empty([3, 4]) print("a = ", a) b = torch.empty([2, 3]) print("b = ", b) Output: a = tensor([[2.0283e-19, 6.9772e+22, 1.8943e+23, 1.1432e-32], [1.3563e-19, 1.8888e+31, 8.9066e-15, 1.8888e+31], [6.4639e-04, 6.8608e+22, 1.7753e+28, 2.0535e-19]]) b = tensor([[0., 0., 0.], [0., 0., 0.]]) Comment More infoAdvertise with us Next Article Python Pytorch empty() method S sanskar27jain Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads 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 is_storage() method PyTorch torch.is_storage() method returns True if obj is a PyTorch storage object. Syntax: torch.is_storage(object) Arguments object: This is input tensor to be tested. Return: It returns either True or False. Let's see this concept with the help of few examples: Example 1: Python3 # Importing the P 1 min read Python - PyTorch is_storage() method PyTorch torch.is_storage() method returns True if obj is a PyTorch storage object. Syntax: torch.is_storage(object) Arguments object: This is input tensor to be tested. Return: It returns either True or False. Let's see this concept with the help of few examples: Example 1: Python3 # Importing the P 1 min read Python Set clear() Method Python Set clear() method removes all elements from the set. Python Set clear() Method Syntax: Syntax: set.clear() parameters: The clear() method doesn't take any parameters. Â Return: None Time complexity : The time complexity of set.clear() function on a set with n element is O(n) . Example 1: Pyth 2 min read Python | getattr() method The getattr() method in Python returns the value of a named attribute of an object. If the attribute is not found then it returns the default value provided. If no default is given and the attribute does not exist then it raises an AttributeError.Python getattr() Method SyntaxSyntax : getattr(obj, k 3 min read Python setattr() method Python setattr() method is used to assign the object attribute its value. The setattr() can also be used to initialize a new object attribute. Also, setattr() can be used to assign None to any object attribute. Example : Python3 class Person: def __init__(self): pass p = Person() setattr(p, 'name', 3 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 __len__() magic method Python __len__ is one of the various magic methods in Python programming language, it is basically used to implement the len() function in Python because whenever we call the len() function then internally __len__ magic method is called. It finally returns an integer value that is greater than or eq 2 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