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

5 PyTorch functions

These are 5 pytorch functions to make your life easier

  • chunk
  • arange
  • rand
  • round
  • rsqrt

Before we begin, let's install and import PyTorch

# Import torch and other required modules
import torch

Function 1 - torch.chunk

splits a tensor into different chunks

torch.chunk(torch.rand(20), 3)
torch.chunk(torch.rand(15), 3)
(tensor([0.2409, 0.3073, 0.4163, 0.1516, 0.1519]),
 tensor([0.6343, 0.9780, 0.9053, 0.6880, 0.6532]),
 tensor([0.8946, 0.4391, 0.6168, 0.7881, 0.9527]))

in the example above the tensor is split into chunks of 3