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

Assignment 1 All About torch.Tensor

Submission for "Deep Learning with PyTorch: Zero to GANs"

PyTorch is an open source Machine Learning library by Facebook. In this notebook I will try to explain following tensor functions from PyTorch library.

  • random_()
  • squeeze (unsqueeze)
  • torch.cat
  • torch.where
  • torch.linspace()
# Import torch and other required modules
import torch

Function 1 - random_()

Fills the tensor with random values. If not specified uses the bounds of the dtype of the tensor.

tensor = torch.empty((3,3), dtype=torch.int8)
tensor.random_()
tensor([[15, 48, 94],
        [27, 68, 84],
        [25, 57, 57]], dtype=torch.int8)

Creates a 3x3 int tensor and fill the tensor with random values