What Is a Matrix?
At first glance a matrix is just a rectangular grid of numbers, written in square
brackets:
A = \begin{bmatrix} 2 & -1 & 0 \\ 3 & 5 & 4 \end{bmatrix}.
But that grid is secretly a machine. Feed a matrix a vector and it hands back a
new one — stretched, rotated, squashed or flipped. The very same idea, scaled up to enormous grids,
is what rotates a photo on your phone, blurs a video call's background, tells a robot arm how to
move its joints, and — in the form of one famously gigantic matrix — decides which web pages Google
shows you first. A matrix isn't a table you read; it's an instruction you run. Before we
can run one, though, we need to be fluent at reading one — so that's where we start.
A matrix's size is given as rows × columns. The matrix above is
2 \times 3 — two rows, three columns. We name the entry in row
i, column j as
a_{ij}; here a_{12} = -1 and
a_{23} = 4. Row first, then column — always.
Reading the grid: rows, columns, dimensions
A row runs left to right; a column runs top to bottom. When we
state a matrix's dimensions we always say rows first: an
m \times n matrix has m rows and
n columns, giving it m \times n entries in
total, one for every row–column pairing. The entry a_{ij} lives where
row i crosses column j — think of it like a
seat number in a theatre: row number first, seat-along-the-row number second.
The lowercase letter matches the matrix's capital: entries of A are
called a_{ij}, entries of a matrix B would be
b_{ij}, and so on. Subscripts i and
j are just placeholder names for "whichever row" and "whichever
column" — swap in actual numbers, like a_{31}, and you're pointing at
one specific entry. Rows are always counted starting from the top, columns always starting from the
left, so a_{11} is forever the entry in the top-left corner.
- An m \times n matrix has m rows and n columns.
- Its entry a_{ij} sits in row i, column j — row index always comes first.
- It has exactly m \times n entries in total.
Worked example 1: naming the size
Count rows top-to-bottom, then columns left-to-right, for each of these:
P = \begin{bmatrix} 3 & 1 \\ 0 & -2 \end{bmatrix}, \quad Q = \begin{bmatrix} 5 \\ 2 \\ 7 \end{bmatrix}, \quad R = \begin{bmatrix} 4 & -1 & 6 & 2 \end{bmatrix}, \quad S = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}.
P has 2 rows and 2 columns: it's 2 \times 2.
Q has 3 rows but only 1 column: 3 \times 1 —
all column, no width, so we call it a column vector.
R flips that: 1 row, 4 columns, so
1 \times 4 — a row vector. And
S has 3 rows and 3 columns, 3 \times 3: equal
rows and columns makes it a square matrix (this particular one, with 1s down the
diagonal and 0s elsewhere, is special enough to have its own name later on). Notice how easy it is
to get Q and R backwards if you don't count
carefully — they hold the same four numbers arranged in opposite shapes.
Worked example 2: find the entry
Take the very first matrix again, A = \begin{bmatrix} 2 & -1 & 0 \\ 3 & 5 & 4 \end{bmatrix},
and read off a few entries by hand before touching anything. Row 1 is
(2, -1, 0) and row 2 is (3, 5, 4). So
a_{12} means row 1, column 2: scan along row 1 to the second slot, and
you land on -1. Meanwhile a_{21} means row 2,
column 1: scan along row 2 to the first slot, and you land on 3.
Same two digits, "1" and "2" — swap their order and you land on a completely different number. That
is exactly why the convention row first, then column has to be non-negotiable.
Now dial a row and a column below and watch the highlighted cell track your choice. Get used to the
convention — countless bugs in real code come from swapping row and column indices.
Worked example 3: a matrix hiding in a mark sheet
You don't need square brackets to be looking at a matrix — any grid of related numbers qualifies.
A teacher's mark sheet for three students across three subjects is a genuine
3 \times 3 matrix S, students as rows and
subjects as columns:
|
Maths |
Science |
Art |
| Ann |
82 |
91 |
75 |
| Ben |
67 |
88 |
92 |
| Cara |
95 |
79 |
84 |
Number the rows Ann, Ben, Cara (1, 2, 3) and the columns Maths, Science, Art (1, 2, 3). Ben's
Science score is entry a_{22} — row 2 (Ben), column 2 (Science) — which
the table shows is 88. Try it yourself: what is
a_{33}, Cara's Art score? Row 3 is Cara, column 3 is Art, and the table
reads 84. Spreadsheets, databases and grade books are matrices wearing
everyday clothes.
Notice the choice of "students as rows, subjects as columns" was ours to make — we could just as
easily have flipped it, with subjects as rows and students as columns. Nothing about the numbers
forces one layout over the other. What matters is picking a convention and being explicit about it,
because a_{23} in the students-as-rows layout is a completely different
score from a_{23} in the subjects-as-rows layout, even though it's the
exact same table of marks underneath.
Shape decides what a matrix can do
Two special shapes matter most. A matrix with one column is exactly a
column vector
— so vectors are just skinny matrices — and a matrix with one row is a row vector, its sideways
twin. A square matrix has as many rows as columns, and those are the ones that can
act as
transformations
of a space onto itself: a 2 \times 2 matrix can rotate or stretch the
2-D plane, sending every point to a new point in that same plane. A non-square matrix,
like our 2 \times 3 example, instead moves between spaces of different
sizes altogether. Shape decides what a matrix is allowed to do — long before we ever multiply
anything.
-
a_{ij} always means row i,
column j — row first, column second, no exceptions. It's
the single most common slip when reading matrix notation: mixing up
a_{12} and a_{21} silently swaps two
different numbers.
-
An m \times n matrix has m rows
and n columns — not the other way round. A
3 \times 2 matrix is tall and narrow (3 rows, 2 columns); a
2 \times 3 matrix is short and wide (2 rows, 3 columns). They are
not the same shape, even though they share the same two numbers.
-
One memory trick: read "rows × columns" the same way you read a page — down, then
across. You count how far down (rows) before you count how far
across (columns), in both the size and every a_{ij}.
In the late 1990s, Google's founders modelled the entire web as one colossal matrix: one row and
one column for every web page, with an entry recording whether page i
links to page j. Their famous PageRank algorithm boils
down to repeatedly multiplying this giant matrix by a vector of "importance scores" until the
scores settle down — pages linked to by many important pages end up important themselves. The
matrix has billions of rows and columns, but the underlying idea is exactly the row-and-column
bookkeeping you just practised above, just scaled up almost unimaginably far.
Closer to home: every photo on your phone is also a matrix (or, for colour, three of
them stacked — one each for red, green and blue). Each entry is a pixel's brightness, and its
row/column position is exactly its position in the picture. Rotate the photo, blur it, or brighten
it, and your phone is running matrix arithmetic on that grid faster than you can blink.
Even the word "matrix" has a fittingly grand backstory. The mathematician James Joseph Sylvester
coined it in 1850, borrowing the Latin word for womb — to him, a matrix was the grid from
which whole families of numbers (called determinants) could be "born". Grids of numbers for
solving several equations at once are far older still: a Chinese text called The Nine
Chapters on the Mathematical Art, compiled roughly two thousand years ago, already arranges
coefficients in rows and columns and manipulates them almost exactly the way we do today —
centuries before anyone had a word for it.
See it explained