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

Just a few Pytorch Functions

Pytorch helps us create tensors which in turn creates matrices which will help us in building models. The functions chosen are just the tip of the iceberg of what pytorch can do.

  • torch.linspace
  • torch.chunk
  • torch.inverse
  • torch.dot
  • torch.det

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.linspace

Creates a one dimensional tensor of our desired steps and limits

# Example 1 - working 
torch.linspace(5,25,steps= 4)
tensor([ 5.0000, 11.6667, 18.3333, 25.0000])