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

Pytorch 101 - Deep Learning from Zero to GAN

Assignment 1

An short introduction about PyTorch and about the chosen functions.

  • torch.eye
  • torch.sparse
  • torch.argmax()
  • torch.argsort()
  • torch.reshape
# Import torch and other required modules
import torch

Function 1 - torch.eye

This function can be used in many matrix calculations wherein we can incorporate identity matrix to enable the matrix operation and convert the resulting matrix dimensions.

# the identity matrix having dimension (5,5) with values 1
a = 1 * torch.eye(5)
a
tensor([[1., 0., 0., 0., 0.],
        [0., 1., 0., 0., 0.],
        [0., 0., 1., 0., 0.],
        [0., 0., 0., 1., 0.],
        [0., 0., 0., 0., 1.]])
b = 4 * torch.eye(-1)
b
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-3-d1e2439de3bd> in <module> ----> 1 b = 4 * torch.eye(-1) 2 b RuntimeError: n must be greater or equal to 0, got -1