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

Mind Blowing functions of Pytorch

Some common but useful mind blowing functions of Pytorch library which might useful in your next project.

  • torch.tensor()
  • torch.from_numpy()
  • torch.sin()
  • torch.cat()
  • torch.where()

Before we begin, let's install and import PyTorch

# Import torch and other required modules
import torch

Function 1 - torch.tensor ()

torch.tensor() is probably the first function when anybody starts with Pytorch.
This function create a tensor with the given inputs.

# Example 1 - working ()
t1= torch.tensor([[1, 2], [3, 4.]])
t1
tensor([[1., 2.],
        [3., 4.]])
t1.dtype
torch.float32