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

Get to Know PyTorch

This notebook is about a short introduction of PyTorch and the chosen functions.

  • torch.randn()
  • torch.arange()
  • torch.linspace()
  • torch.sum()
  • reshape()

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.randn()

This function returns a tensor filled with random integers tensor matrix

# Example 1 - working
a = torch.randn(3,2)
a
tensor([[ 0.5942,  0.3288],
        [ 0.8544,  1.1420],
        [ 0.0543, -0.1330]])