PyTorch: Introduction
PyTorch is an opensource machine learning library used for developing and training neural network based deep learning models.
PyTorch is known for providing two most high level features:

  1. Tensor computation that uses the power of Graphic Processing Units and
  2. Building deep neural networks on a tape based autograd system.
    In the past few years, PyTorch has helped accelerate the research that goes into deep learning models by making them computationally faster using dynamic computation that allows greater flexibility in building complex architecture.

Tensor in PyTorch
Tensor is a generic n-dimensional array to be used for numeric computation It is basically same as numpy array however, former can run on either device i.e. CPU or GPU. To run operations on GPU, just cast the Tensor to a cuda datatype.

PyTorch supports multiple types of tensors :

  1. FloatTensor - 32-bit float
  2. DoubleTensor - 64-bit float
  3. HalfTensor - 16-bit float
  4. IntTensor - 32-bit int
  5. LongTensor - 64-bit int

Here we will go through tensor and some of it's basic functions.

  • torch.randn()
  • torch.reshape()
  • torch.pow()
  • torch.eq()
  • torch.var_mean()
# Import torch and other required modules
import torch

Function 1 - torch.randn()

torch.randn function generates a tensor filled with random numbers from a normal distribution with mean'0' and variance '1'.
Signature:
torch.randn(*size,out,dtype,device,requires_grad)
size is the mandatory parameter for randn(). Rest other parameters are optional. Let's see how this function and it's arguments work.

# Example 1 - working (change this)
a = torch.randn([4,5], dtype=torch.float64)
a
tensor([[ 1.8899,  0.0402,  2.2968, -1.1872, -1.6987],
        [-0.3485, -0.7383,  0.5017, -0.0750,  1.2717],
        [ 0.0699, -0.6585,  0.5147, -1.7821, -1.6673],
        [-0.8019, -0.2728, -0.0230,  0.5903, -0.1845]], dtype=torch.float64)
#Here in this example we created a random tensor using the .randn() function. We passed the parameter size(int,int): a sequence of integer defining the shape of output tensor and dtype as the desired datatype of output tensor. The default dtype is float.32 it can be checked using function: torch.get_default_dtype()