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

Some Pytorch functions

These functions below will be discussed in this notebook

  • torch.to_tensor
  • torch.from_numpy
  • torch.cat
  • torch.masked_select
  • torch.chunk
# Import torch and other required modules
import torch
import numpy as np

Function 1 - torch.as_tensor

Copies the elements of a list into a tensor.

a_list = [1, 2, 3]
a_tensor = torch.as_tensor(a_list)
a_tensor.add_(a_tensor), a_list
(tensor([2, 4, 6]), [1, 2, 3])