Understanding tensors
In the MNIST example, the digit images were stored in NumPy matrices, also called tensors. These tensors are the basic data structures for machine learning models. Now that we know what fuels our models, let's dig deeper into understanding what tensors are and their different types.
What is a tensor?
A tensor is basically a multi-dimensional array of numbers, usually floating-point numbers of N dimensions (also called axes).
A tensor is defined by three key attributes: the number of axes or rank, the dimension of each axes or shape, and the type of data it contains. Let's explain them in detail:
- Rank (axes number): This is also called a dimension in
numpy
nomenclature (ndim
). For instance, a scalar (a single number) has no axes, a vector (a list of numbers) has one, a matrix (a list of vectors) has two, and a 3D tensor (a list of matrices) has three. Let's look at a practical example:>>> import numpy as np >>>...