← Learn AI
C_000390 · mathematical foundations · intermediate

Tensors and Shapes

Multi-dimensional arrays and the discipline of tracking their dimensions through a computation.

Step 1 of 4

In words

What it is, why it matters, and what it is like.

Why am I learning this?

If you have ever tried to combine two sets of data—like matching a list of customer names with their order histories—or built a model that predicts outcomes from multiple inputs, you have encountered the problem this concept solves. Modern tools for pattern recognition and prediction rely on organizing numbers into structured blocks called tensors. Understanding what a tensor is, and specifically how its dimensions (its shape) behave, is the single most important skill for fixing errors in these systems. When a model fails because the data structures do not align, knowing exactly why that happened allows you to fix it quickly. This page gives you the foundation to understand those alignment issues and prevents the confusion that comes when you later encounter complex models like neural networks or language processors.

The idea, in plain terms

You already use the idea of multi-dimensional organization in your daily work. Think of a spreadsheet. A single sheet with rows and columns is a table, which mathematicians call a 2-dimensional array. Now imagine you have a folder full of these spreadsheets—perhaps one for each month of the year. If you look at all those sheets together as one unit, you have created a 3-dimensional array: a stack of tables. A tensor is simply the name for any collection of numbers arranged in this way, regardless of how many layers it has. It can be 1-dimensional (a simple list), 2-dimensional (a table), 3-dimensional (a stack of tables), or even more layers deep.

What matters most is the shape. The shape is a list of numbers that tells you exactly how many items exist in each layer. For example, a spreadsheet with 10 rows and 5 columns has the shape (10, 5). If you take 20 of those identical spreadsheets and stack them, the resulting 3-dimensional tensor has the shape (20, 10, 5). This shape is not just a label; it is a strict promise about the structure of your data. Every time you perform an operation on this tensor—whether you are adding two tensors together or processing them through a model—the result must follow specific rules dictated by these shapes. Tracking the shape is like checking that two puzzle pieces fit before you try to push them together. You need to know which dimension represents what (e.g., time, category, or sample) to ensure the operation makes sense.

An analogy

Think of a warehouse organizing crates of identical products. A single crate is a box with length and width. To store many crates, you stack them on shelves; a shelf is a row of these crates. To organize many shelves, you line them up in aisles. This creates a 3-dimensional structure: the aisle represents the first dimension, the shelf the second, and the position within the shelf the third. When you take a crate from one location and move it to another, you must know the dimensions of the container to ensure it fits. Similarly, when you combine data in computing, the shapes must align perfectly, or the operation cannot proceed. The analogy breaks down only when tensors have more than three dimensions—computers can handle four, five, or even fifty dimensions easily, whereas we cannot physically visualize them. However, the core idea remains the same: higher dimensions are just nested layers of lists, each layer having its own size.

Definition

A tensor is a multi-dimensional array of numbers, and its shape is the sequence of integers that specifies how many elements exist along each dimension.

Where this sits

You know that in everyday life, a list of numbers is just a list, and a table of numbers is a table. A tensor generalizes this: it is a container that holds numbers in any number of dimensions, allowing you to treat a simple list, a table, and a stack of tables under one unified concept. This serves as the entry point into linear algebra, which is the branch of mathematics concerned with vectors (lists) and matrices (tables), and how they interact. In artificial intelligence, all data—whether a batch of images, a sequence of words, or a table of features—is organized as tensors. The shape of a tensor acts like the dimensions of a physical box, telling you exactly how many items fit in each direction. This understanding is essential for later topics involving the combination of these structures, where specific rules about their shapes determine whether operations are mathematically valid.

Signal from the Frontier

Get the next essay on mind, machine, and meaning

Essays at the intersection of AI, philosophy, and Indian governance. No promotional content.

We'll send a one-click sign-in link to confirm. No password needed.

Views expressed are personal and do not represent the Government of India or the Government of Uttarakhand.

Tensors and Shapes — Learn AI — Dr. B.V.R.C. Purushottam