Open In App

Python – PyTorch is_storage() method

Last Updated : 26 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatStorage(6)
print(a)
  
# Applying the is_tensor function and 
# storing the result in 'out'
out = torch.is_storage(a)
print(out)


Output:

-30587.265625
 4.555761437366413e-41
 3.906847023468105e-37
 0.0
 4.484155085839415e-44
 0.0
[torch.FloatStorage of size 6]
True

Example 2:




# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.randn(4, 6)
print(a)
  
# Applying the is_tensor function and 
# storing the result in 'out'
out = torch.is_storage(a)
print(out)


Output:

0.4837 -0.3108  0.5945 -0.5967  1.0831  0.0967
-0.0174  0.4937  0.9900 -0.0532 -0.4830 -0.4711
 1.3607 -1.0815  0.4421 -0.2668 -0.5778 -0.0482
-2.0869 -0.8338  1.2260 -0.8849  0.7303 -1.0050
[torch.FloatTensor of size 4x6]
False

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads