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

Introduction to Pytorch

Pytorch is a Python-based scientific computing package targeted at two sets of audiences:

  • A replacement for NumPy to use the power of GPUs
  • a deep learning research platform that provides maximum flexibility and speed

The functions chosen for this assignment are the basic functions that were likely to be used in the future, and are as follows

  • torch.zeros
  • torch.ones
  • torch.arange
  • torch.eye
  • torch.complex

Before we begin, let's install and import PyTorch

# Uncomment and run the appropriate command for your operating system, if required

# Linux / Binder
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# Windows
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# MacOS
# !pip install numpy torch torchvision torchaudio
# Import torch and other required modules
import torch

Function 1 - torch.zeros

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size

i = torch.zeros(2,3)
i
tensor([[0., 0., 0.],
        [0., 0., 0.]])