The torch.Tensor.untyped_storage() method returns the underlying torch.UntypedStorage of a tensor, which is a contiguous, one-dimensional array of bytes. It is different from torch.Tensor.storage, which returns a torch.TypedStorage that has a specific data type. The torch.TypedStorage is deprecated and will be removed in the future.
Syntax
Tensor.untyped_storage()
Example
import torch
# create a tensor of shape (2, 3) with random values
x = torch.rand(2, 3)
print(x)
# get the untyped storage of the tensor
s = x.untyped_storage()
print(s)
# get the size and type of the storage
print(s.size())
print(s.type())
Output
That’s it!

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Machine Learning frameworks like PyTorch and Tensorflow is a testament to his versatility and commitment to the craft.