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

ZeroToGANs: Assignment-1

Understanding PyTorch

A short introduction to some functions in PyTorch

  1. torch.dot
  2. torch.histc
  3. torch.sigmoid
  4. torch.argmax
  5. torch.transpose
!pip install jovian --upgrade --quiet
!pip install matplotlib --quiet
# Import torch and other required modules
import torch
import matplotlib.pyplot as plt

Function 1 - torch.dot

Returns the dot product of 2 tensors. Takes 2 arguments -

  • input: the first 1D tensor
  • tensor: the second 1D tensor

Official Documentation

Note:
  • this function expects 1-dimensional tensors only
  • this function does not broadcasts, i.e., its Tensor arguments CANNOT be automatically expanded to be of equal sizes (without making copies of the data).
# Example 1 - working
x = torch.tensor([4., 5., 2., 3.])
y = torch.tensor([2., 3., 1., 5.])
torch.dot(x, y)
tensor(40.)