5 Usefull PyTorch Functions
Introduction to PyTorch
Every once in a while, there comes a library or framework that reshapes and reimagines how we look at the field of deep learning. The remarkable progress a single framework can bring about never ceases to amaze me.
I can safely say PyTorch is on that list of deep learning frameworks. It has helped accelerate the research that goes into deep learning models by making them computationally faster and less expensive (a data scientist’s dream!).
At its core, the development of Pytorch was aimed at being as similar to Python’s Numpy as possible. Doing so would allow an easy and smooth interaction between regular Python code, Numpy, and Pytorch allowing for faster and easier coding.
- torch.unique()
- torch.ceil()
- torch.numel()
- torch.mm()
- torch.exp()
# Import torch and other required modules
import torch
Function 1 - torch.unique()
torch.unique() removes the dublicats from the tensor. It is pretty useful when you want to work on unique data.
Its returns the tensor of 1 dim of unique elements even if your tensor is multi dimensional.
# Example 1 - working (change this)
x=torch.tensor([[1, 2,5,2,5], [3, 4.,3,2,5]])
x
torch.unique(x)
tensor([1., 2., 3., 4., 5.])
In this exammple i used 2x5 dimensional tensor but it returned 1x1 dimensional with unique elements