#native_company# #native_desc#

What are Tensors?

Let's get physical

Sometimes, nothing beats holding a copy of a book in your hands. Writing in the margins, highlighting sentences, folding corners. So this book is also available from Amazon as a paperback.

Buy now on Amazon

Tensors are the building blocks of a machine learning model. They are nothing to be scared of; you’ve most likely been using them for a while but have never called them Tensors.

They are a set of numbers of a specific size and shape.

So far, we’ve explained how neural network models are just functions that manipulate numbers, a set of input numbers of a specific size, into a set of output numbers into another size and shape. Tensors are how we represent those numbers, the inputs, the outputs, and everything in between.


The dimensionality of a Tensor we call it’s rank.

A 1D Tensor (or rank 1 Tensor) is just an array, like so:

1d tensor

A 2D Tensor (or rank 2 Tensor) is just a 2-dimensional array, so an array of arrays, like so:

2d tensor

A 3D Tensor (or rank 3 Tensor) is a cube. An array of arrays of arrays, like so:

3d tensor

Everything after 3D becomes harder to conceptualize, but let’s try. A 4D Tensor is an array of 3D Tensors, like so:

4d tensor

A 5D Tensor is an array of 4D Tensors, like so:

5d tensor


The size of each dimension in a Tensor we call its shape. For example, a Tensor to represent a black and white image would have the shape [width, height, colors].

For a 640 x 480 pixel black and white image, the shape would be [640,480, 1].

colors in this case would be of size 1; in a black and white image, the only color is black; in a color image, the size might be 3 with a value for red, green, and blue.

The rank of the Tensor is 3; it’s a 3D Tensor.

How to represent a data set of images?

For one type of machine learning, supervised learning[1], we provide large sets of training data for our machine learning models.

We represent a single black and white image as a 3D Tensor of shape [width, height, color].

We represent a set of 1000 black and white image as a 4D Tensor of shape [sample_size, width, height, color].

For example, a set of 1000, 640 x 480 pixel black and white images would be represented as 4D Tensor of Shape [1000, 640, 480, 1].


Tensors are just buckets of numbers of a specific shape and a certain rank (dimensionality). Tensors are used in Machine Learning with TensorFlow to represent input data and output data (and everything in between) in Machine Learning models.

Advanced JavaScript

This unique course teaches you advanced JavaScript knowledge through a series of interview questions. Bring your JavaScript to the 2021's today.

Level up your JavaScript now!