Introduction

PyTorch is a Python library that facilitates building **Deep Learning models. **It was introduced by Facebook. PyTorch is used for a number of applications like Natural Language Processing, Computer Vision, Self-driving cars, etc.

The basic building block of PyTorch is Tensors. In simple words, a Tensor is an array of numbers. In the NumPy library, these matrices are called nd-array. In PyTorch, 1d-tensor is a vector, 2d-tensor is a matrix, 3d- Tensor is a cube, and 4d-Tensor is a cube vector.

Basic Functions of PyTorch:

  1. Creation and Slicing of Tensor -

Import PyTorch module as “import torch_”. _For creating an n-dimensional tensor, we use the tensor function of torch module ie,torch.tensor([elements]).

_Note: _In PyTorch, tensors should be symmetric like 3,3. If the elements are of different shape, the compiler raises sequence exception.

  • A Tensor can be initialized only with numbers. It can not contain any strings or characters.

Tensor can only have numerical data.

Intializing tensor with a string thows exception

k = torch.tensor([‘snehit’])

ValueError Traceback (most recent call last)
in
1 # Tensor can only have numerical data.
2 # Intializing tensor with a string thows exception
----> 3 k = torch.tensor([‘snehit’])

ValueError: too many dimensions ‘str’
Hosted on Jovian.ml
View File

#python3 #pytorch #machine-learning

Basic Important Functions Of PyTorch | PyTorch Series | Week-1 |
10.90 GEEK