Learn practical skills, build real-world projects, and advance your career

Deep Learning building blocks: 5 popular torch tensor functions

Hi all, in this short introduction about PyTorch, I decided to explore 5 main functions that are a must in most of Deep Learning models nowadays:

  • torch.view()
  • torch.reshape()
  • torch.permute()
  • torch.flatten()
  • torch.cat()

Particularly, I chose them not only because they are famous, but also because some of them can generate some confusion as they behave quite similarly.

import torch
import jovian

Function 1 - torch.view()

This function returns a new tensor with the same data as the original tensor but of a different shape.

tensor1 = torch.tensor([[1, 2], [3, 4.]])
tensor1
tensor([[1., 2.],
        [3., 4.]])

Imagine we want to reshape our tensor to a (1, 4) shape