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

Pytorch Bootcamp

Pytorch is at the forefront in the development deep learning and neural networks and in essence is a package that consists of modules such as torch.nn, torch.optim to develop, train and deploy your deep learning algorithms. TO that that effect, i've chosen 5 functions that reflect the vast potential with which these tools have been develeped, particularly aimed at beginers (like me!).

  • new_ones()
  • view()
  • matrix_power()
  • numel()
  • linspace()
# Import torch and other required modules
import torch

Function 1 - new_ones

This function returns a tensor object with the specified dimensions as arguments, and all the elements are initialised to one.

t1 = torch.tensor((),dtype=torch.int32)
t1.new_ones(5)
tensor([1, 1, 1, 1, 1], dtype=torch.int32)

This creates a 1d tensor of length 5