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

5 Interesting Pytorch Functions:

Pytorch is an open sourced Machine Learning Library developed on the torch library and maintained by Facebook. Below are 5 of the commonly used pytorch functions which a Deep Learning practitioner should be aware of:

  1. torch.tensor.numpy() :- torch.tensor.numpy() is used to convert a tensor to a numpy array
  2. torch.tensor.new_tensor() :- torch.tensor.new_tensor() is used to create a new tensor from an existing tensor or a data collection.
  3. torch.tensor.view():- torch.tensor.view() is used to get a view of the existing tensor without explicit memory copy of the tensor data.
  4. torch.tensor.is_leaf :- torch.tensor.is_leaf is used to detect whether a tensor is a leaf Tensor or not.
  5. torch.tensor.backward():- torch.tensor.backward() calculates the gradient of current tensor w.r.t leaf tensor.

Below, we will explore the working code examples of each of the above mentioned function in pytorch along with one drawback for each.

                                    Let's Start!!! 

Import the required libraries

import torch
import numpy as np

Which version of Python is used??

!python --version      ##running version of python
Python 3.7.7