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

Deep Learning With Pytorch-First Assignment

Explanation About Five Useful Pytorch Tensor Functions

PyTorch is an open source machine learning library based on the Torch library,used for applications such as computer vision and natural language processing,primarily developed by Facebook's AI Research lab (FAIR).

Functions we will be going through in this notebook

  • torch.randn()
  • torch.linspace()
  • torch.reshape()
  • torch.t()
  • torch.sum()
# Import torch and other required modules
import torch

Function 1 - torch.randn()

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1
# Example 1 - working
x=torch.randn(4)
x
tensor([0.9129, 0.5168, 0.8577, 1.3322])

As we can see here,we got a tensor of size 4 (1D) with the values between 0 and 1