# Scalars, vectors, matrices & tensors

> A thermostat reading, a drone's position, a thermal camera, and a phone video—all numbers arranged in different ways.

Type: lesson
Canonical: https://nithinraphael.com/learn/machine-learning/scalars-vectors-matrices-tensors
Parent: machine-learning
Status: published

---

# Scalars, vectors, matrices & tensors

A thermostat reading. A drone’s position. A thermal camera. A phone photo.

They seem completely different in the real world—but underneath, they’re all **numbers organized in different ways**.

As the information becomes more complex, we need more ways to organize those numbers. That takes us from **scalar → vector → matrix → tensor**.

***

## Scalar

Sometimes, **one number is enough**.

A room temperature of `22°C` can be described completely with a single value. That makes it a **scalar**.

Scalars appear everywhere: speed, distance, price, battery percentage, temperature, and many other measurements can all be represented by one number.

> Interactive component: Scalar Interactive.

No matter where you move the slider, the room temperature is still described by **one value**.

`22°C` → **Scalar**

A scalar answers a simple question:

**How much?**

But one number stops being enough when we need to describe something like a position.

***

## Vector

Imagine telling a delivery drone where to go.

One number cannot describe its position on a flat map. The drone needs both a **horizontal position** and a **vertical position**.

We can store those values together:

`[x, y]`

That ordered list of values is a **vector**.

For example:

`[6, 3]`

could mean 6 units across and 3 units up.

> Interactive component: Vector Interactive.

Move horizontally and one value changes.

Move vertically and another value changes.

Together, the numbers describe **one position**.

The order matters. `[6, 3]` and `[3, 6]` point to different locations because each value has a different role.

Vectors are useful for more than positions. They can represent things like:

- velocity: `[vx, vy]`
- GPS-style coordinates: `[latitude, longitude]`
- a pixel’s color: `[red, green, blue]`
- a point in 3D space: `[x, y, z]`

A vector gives us several related values arranged along **one axis**.

What if we need many values arranged both across and down?

That gives us a matrix.

***

## Matrix

A thermal camera does not measure just one point.

It measures temperatures across an entire area, producing values arranged in **rows and columns**.

For example:

```text
21  22  24  25
20  23  29  31
19  22  27  28
```

This two-dimensional grid of numbers is a **matrix**.

A matrix has two axes:

`rows × columns`

Each value has a location determined by both its row and its column.

> Interactive component: Matrix Interactive.

The temperature itself is still a scalar.

But the complete thermal scan contains many temperatures arranged across two axes, so the entire dataset is a **matrix**.

Matrices show up in many familiar places:

- spreadsheets
- grayscale images
- game maps
- seating charts
- sensor grids
- scientific measurements

A grayscale image, for example, can be stored as a matrix where every number represents the brightness of one pixel.

So a matrix handles rows and columns well.

But a color photo needs something extra.

***

## Tensor

A phone photo may look like one flat image, but the computer stores much more underneath.

Each pixel usually contains separate **red, green, and blue values**.

That means we can think of the image as three grids stacked together:

- one red layer
- one green layer
- one blue layer

Now the data has three axes:

`height × width × channels`

This multi-axis collection of values is a **tensor**.

> Interactive component: Tensor Interactive.

Each individual color layer is matrix-like.

Stack the three matrices together and you add another axis: **color channel**.

For example:

`1080 × 1920 × 3`

could describe an image that is:

- 1080 pixels high
- 1920 pixels wide
- 3 color channels

Tensors can have even more axes.

A video adds time:

`time × height × width × channels`

A machine-learning model processing several images at once might use:

`batch × height × width × channels`

This is why tensors are so common in **machine learning and deep learning**. Images, video, audio, and other complex datasets often need several axes to organize all their values.

The word *tensor* may sound advanced, but the basic idea is straightforward:

**more axes, same basic ingredient: numbers.**

***

## The pattern

The easiest way to remember the progression is to focus on how the values are organized.

- **Scalar** — one value
- **Vector** — values along one axis
- **Matrix** — values across two axes
- **Tensor** — values organized across additional axes

Think of it as adding structure:

`22°C`

**Scalar:** one value

`[6, 3]`

**Vector:** an ordered list

```text
21  22  24
20  23  29
19  22  27
```

**Matrix:** rows and columns

`height × width × channels`

**Tensor:** multiple axes

The numbers themselves are still ordinary numbers. We have simply added more ways to organize them.

A useful question to ask whenever you encounter a new dataset is:

**How many axes do I need to organize the values?**

That question can often tell you which structure you are looking at.

***

> Interactive component: Matching Quiz.
