Machine Learning : Basic of PyTorch

Original article was published on Deep Learning on Medium

PyTorch is one of the most popular machine learning library and It is developed by Facebook AI Research team.

Setup and Installation of PyTorch

We’ll install PyTorch using Anaconda Distribution. First we’ll install Anaconda Distribution. And then we’ll install PyToch using conda command.

Conda to install PyToch

Once the virtual environment is active and installed pytorch, we can start Jupyter by running:

(pytorch) C:\Users\DoHS>jupyter notebook

We can access Jupyter notebook’s interface in browser by just opening http://localhost:8888

Root directory of Jupyter Notebook

Now If you want to type out the code, you can create a new notebook using the ‘New’ button.

Let’s begin just by importing Pytorch library:

import torch


Tensor is basically the same as a numpy array with some extra feature than numpy array. It is used to create multi-dimensional matrix. Which is useful in developing machine learning model.

Some useful function to create Tensor


It is used to create tensor with random value of given shape and size.


It is another function to create tensor. In this function it will concatenates the sequences of tensor similar dimension.


The torch.reshape() function will return the tensor on given shape structure. The given shape should be equal to original tensor shape.

We can found many more useful tensor function from PyTorch official website.