Lesson 1 of 7
Matrices as data and transformations
A matrix is a rectangular table of numbers and also a machine that transforms vectors.
Core lesson · about 6 minutes · 3 guided parts
A class marks table stores one student per row and one subject per column. The same rectangular idea can describe a machine that stretches a drawing's x- and y-coordinates.
Your learning route
Build the idea one piece at a time
- Shape, entries, rows, and columns
- Matrix-vector transformation
- Use one table as both data and a transformation
Shape, entries, rows, and columns
Matrix shape tells what can go in and what comes out.
An m×n matrix has m rows and n columns. Entry aᵢⱼ sits in row i, column j.
Matrices of the same shape add entrywise; scalar multiplication scales every entry.
A data matrix commonly uses rows for examples and columns for features, but the convention must be stated.
A matrix shape is part of its meaning, not decoration. A 30×4 classroom table can represent 30 students and 4 measurements, while transposing it changes which index names a student.
Rows and columns must keep a consistent label order. Adding matrices is meaningful only when corresponding entries describe the same kind of quantity.
A matrix can store relationships as well as data. An adjacency matrix uses entry aᵢⱼ to record whether object i connects to object j.
A∈ℝᵐˣⁿ maps ℝⁿ to ℝᵐWorked example
For A=[[1,2,3],[4,5,6]], state its shape and compute 2A.
- A has 2 rows and 3 columns, so its shape is 2×3.
- Multiply every entry by 2.
- The first row becomes [2,4,6].
- The second becomes [8,10,12].
Answer: Shape 2×3; 2A=[[2,4,6],[8,10,12]].
Matrix-vector transformation
Each output is a dot product with one row; equivalently, the result combines the matrix's columns.
If A is m×n and x has n entries, Ax has m entries.
The jth component xⱼ scales column j of A, so Ax is a linear combination of columns.
A linear map preserves addition and scaling: A(u+v)=Au+Av and A(cu)=cAu.
Each output entry of Ax is a row of A dotted with x, so every row asks one weighted question about the input. The number of rows therefore equals the number of outputs.
The column view tells the same story differently: x₁ chooses how much of column 1 to use, x₂ scales column 2, and their sum builds the output.
Simple matrices stretch, reflect, rotate, or shear coordinate vectors. Testing the standard basis vectors shows where every axis direction is sent and often reveals the full transformation.
(Ax)ᵢ=ΣⱼaᵢⱼxⱼWorked example
Compute Ax for A=[[2,1],[−1,3]] and x=⟨4,2⟩.
- First row dot x: 2·4+1·2=10.
- Second row dot x: −1·4+3·2=2.
- Collect the outputs in order.
- Ax=⟨10,2⟩.
Answer: ⟨10,2⟩
Practical deep dive for this lesson
Use one table as both data and a transformation
A matrix can store many related measurements, and the same row-by-column rule can transform an entire vector of inputs into outputs.
Rows and columns need named meanings. A 3×4 score matrix might use students as rows and subjects as columns; swapping that convention changes every later operation.
A matrix-vector product takes dot products between matrix rows and the input vector. Each output row therefore forms its own weighted combination of all input components.
Viewed as data, selecting a row retrieves one example and selecting a column retrieves one feature. Viewed as a map, columns show where the coordinate basis vectors are sent.
Shape is a logic check. An m×n matrix accepts an n-component vector and produces an m-component vector.
Image colour conversion, weighted scores, linear predictions, and mixtures all use this operation because several outputs can share the same inputs with different weights.
A bias or fixed offset is not included in a purely linear matrix map unless an extra constant coordinate is added; neural layers commonly calculate Ax+b.
Sparse matrices store only nonzero entries when most relationships are absent, saving memory and computation without changing the mathematical rule.
Numbers in a matrix do not explain themselves. Units, row labels, column labels, and preprocessing decisions are essential parts of a correct interpretation.
y=Ax; yi=Σj aij xjWorked example
A final score uses quiz, project, and exam marks with weights 20%, 30%, and 50%. Use a matrix product to score two students with marks [80,70,90] and [60,95,75].
- Arrange the students as rows in X=[[80,70,90],[60,95,75]].
- Write the weight vector w=⟨0.2,0.3,0.5⟩.
- The shapes are 2×3 and 3×1, so Xw is defined and produces a 2×1 result.
- First score: 80(0.2)+70(0.3)+90(0.5)=16+21+45=82.
- Second score: 60(0.2)+95(0.3)+75(0.5)=12+28.5+37.5=78.
- Thus Xw=⟨82,78⟩.
- The weights sum to 1, so each result is a weighted average on the original mark scale.
- Matrix notation matters because the same calculation works for two students or two million without changing the formula.
Answer: The weighted scores are 82 and 78.
Check your picture
What shape must A have to map a 5-entry vector to a 3-entry vector?
Reveal answer
3×5
This lesson versus the whole chapter
Your topic-specific practical example is above.
The final lesson collects five longer chapter-wide workflows for machine learning, LLMs, trading, physics, and everyday decisions.
Formula shelf
Symbols with meaning
(Ax)ᵢ=ΣⱼaᵢⱼxⱼEach output is a row-vector dot product.
(AB)ᵢⱼ=ΣₖaᵢₖbₖⱼComposes two linear transformations.
(AB)ᵀ=BᵀAᵀTranspose reverses composition order.
det([[a,b],[c,d]])=ad−bcDetects area scaling and invertibility.
rank(A)+nullity(A)=number of columnsAccounts for preserved and collapsed input directions.
Av=λvFinds directions preserved up to scale.
A=UΣVᵀSeparates any matrix into orthogonal input directions, stretch strengths, and output directions.
AᵀAx=AᵀbMakes the residual perpendicular to the column space.
q(x)=xᵀAxMeasures direction-dependent squared size, energy, risk, or curvature.
A⁺=VΣ⁺UᵀReverses nonzero singular stretches for minimum-norm least squares.
ratioᵢ=σᵢ²/Σⱼσⱼ²Measures how much centred variation one principal direction preserves.
Before moving on
You are ready when you can…
- Read matrix shapes and treat a matrix as data and a linear map.
- Multiply matrices in the correct order and use identity and transpose rules.
- Solve linear systems by elimination and identify unique, absent, or infinite solutions.
- Reason about span, independence, basis, dimension, rank, and nullity.
- Classify quadratic forms with positive-definite, semidefinite, and indefinite curvature.
- Compute small SVDs, pseudoinverses, low-rank approximations, and PCA explained-variance ratios.