Better visualizing tensors thanks to cities

Sure, it is easy to see how a scalar, a vector, or a matrix look like! But when it comes to n-dimensional arrays, our “narrow” three-dimensional mind can get stuck! But there are ways to go beyond that limitation… and cities are one of them!

Pierre-Louis Bescond
Towards Data Science
4 min readDec 17, 2020

--

Photo by Kaspars Upmanis on Unsplash

The importance of Arrays in Data Science

All Data Science projects rely on structured data (at least at some point!) and some of the usual libraries to handle this information are called “Numpy” or “Pandas”.

The first one (NumPy) is more generic as it allows to deal with multi-dimensional datasets whereas Pandas offers a nice way to handle tabular (2 dimensions) datasets with indexes and specific functionalities.

The same dataset displayed through NumPy or Pandas
(Image by Author)

If you are new to Data Science, understanding arrays’ structure is mandatory because, for some specific projects, you might end up with datasets in the following shape:

hard_to_visualize_array.shape
(10, 24, 540, 960, 3)

And how are you supposed to mentally visualize a 5 dimensions dataset?

Image by Author

A typical use-case of pictures processing

To illustrate this concept, let’s take a “computer vision” or “image detection” project which is typically the kind of initiative where you might end up with complex datasets.

Why? Because each picture is already a complex set of information, coded as a combination of multiple layers (also called “channels”) like RGB: Red, Green, Blue:

Original Photo by Scott Webb on Unsplash — RGB channels by Author

How do these different layers translate into arrays? The thumbnail below is a 10 x 10 pixels version of…

--

--

Head of Data & Advanced Analytics @ Roquette | Winner of the 1st WorldWide Data Centric Deep Learning Contest | Data Science & Machine Learning Passionate!