# TENSORS…

--

~Hola folks!!! Nice to be back with another post 😊…

Tensor is a data structure. It is a container where 90% are numbers. There are different types of tensors.

Before look what are types of tensors, Let’s look what is Rank, Shape and Size of a Tensor.

**Rank : No. of Axes = No. of dimensions (ndim) = Rank****Shape : How many values can be stored in an axis****Size : Available elements in the shape**

*Let’s move onto Types of Tensors…*

## 0-D Tensors/ Scalers

Scalers or the 0-D (0 Dimension) tensors are the tensors where a single number is stored. It has no direction.

ex: 2

Following code snippet can be used to check the dimension of a Scaler…

import numpy as np

a = np.array(2)

a

a.ndim#output => 0

#size = 1

## 1-D Tensors/ Vectors

Vectors or the 1-D (1 Dimension) tensors are a collection of scalers. It includes list of values.

ex: [1,2,3,4]

Following code snippet can be used to check the dimension of a Vector…

import numpy as np

b = np.array([1,2,3,4])

b

b.ndim#output => 1

#size = 4

Vector dimension gives how many values in the array.

## 2-D Tensors/ Matrices

Matrices or the 2-D (2 Dimension) tensors are a collection of multiple vectors. I.E it includes collection of lists.

ex: [1,2,3][4,5,6][7,8,9]

Following code snippet can be used to check the dimension of a Matrix…

import numpy as np

c = np.array([[1,2,3],[4,5,6],[7,8,9]])

c

c.ndim#output => 2

#shape = (3,3)

#size = 9

## 3-D Tensors/ N-D Tensors/ Cuboids

3-D (3 Dimension) tensors are a collection of matrices. It includes row number, column numbers and a depth i.e. number of matrices.

ex: [ [[1,0,0,0][0,1,0,0]], [[1,0,0,0][0,0,1,0]] ,[[1,0,0,0][0,0,0,1]]] =>

row # * column # * depth = 3 * 2 * 4shape = (3,2,4)

size = 3*2*4 = 24

## 4-D Tensors

Collection of cuboids/ 3-D Tensors is called 4-D Tensor. We can find 4-D tensors in the computer vision domain.

ex: Batch of RGB images

## 5-D Tensors

Collection of 4-D Tensors is called 5-D Tensor.

ex: Batch of videos (collection of frames)

# Conclusion

We just briefly learned about Tensors…

That’s it for now, and please press the clap button if you find this article helpful.

This might be a continuation of a series of Machine Learning Fundamentals.🤞

Special thanks to @Jinendra Bogahawatte