Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python Pytorch empty() method

  • Last Updated : 22 Apr, 2020

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:




# 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.]])

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!