Skip to main content

Posts

Showing posts from June, 2020

Basic introduction to Pytorch

What is Pytorch? Pytorch is an open-source machine learning library developed by Facebook. It allows flexibility and speed for scientific computing for deep learning. Consider it as a replacement of Numpy so that the GPU capability can be used. Tensors? Tensor is the core element of Pytorch and are basically a n-dimensional data container much like Numpy's n-dimensional array. A tensor could be a number, vector, matrix or a n-dimensional array. import torch # Scalar - Integer t1 = torch . tensor ( 5 ) print ( "Tensor is {} with shape {} and data type {} " . format ( t1 , t1 . shape , t1 . dtype )) Tensor is 5 with shape torch.Size([]) and data type torch.int64 # Scalar - Float t2 = torch . tensor ( 5. ) print ( "Tensor is {} with shape {} and data type {} " . format ( t2 , t2 . shape , t2 . dtype )) Tensor is 5.0 with shape torch.Size([]) and data type torch.float32 # Vector t3 = torch . tensor ([ 1. , 2 , 3 ]) print ( "Tensor is