Linear Algebra
Matrices & Matrix Multiplication
Two ways to see a matrix
A matrix is a rectangular grid of numbers, like a spreadsheet:
This one has 2 rows and 2 columns (a "2×2 matrix"). There are two equally important ways to think about matrices:
1. A matrix is a table of data. Each row is one example (a house), each column one feature (size, age). A dataset of 10,000 houses with 20 features is a 10,000 × 20 matrix. When ML engineers say "design matrix", they mean this.
2. A matrix is a function that transforms vectors. Multiplying a vector by a matrix rotates, stretches, flips or squashes it. Every layer of a neural network is a matrix waiting to transform whatever vector arrives.
Matrix–vector multiplication
To compute , take the dot product of each row of with :
A vector went in, a (transformed) vector came out — a matrix is a function. A neural network layer computes exactly
where holds the layer's weights and its biases. Notice this is the multi-dimensional version of from lesson one. The pattern never changes; only the dimensions grow.
Matrix–matrix multiplication
Multiplying matrix (m×n) by matrix (n×p) gives an m×p matrix: entry is the dot product of row of with column of . Two crucial properties:
- Inner dimensions must match — (m×n)(n×p) works; the n's must agree.
- Order matters — in general. Transformations applied in a different order give different results (rotate-then-stretch ≠ stretch-then-rotate).
Composing two transformations = multiplying their matrices. A 50-layer network is (roughly) 50 matrix multiplications chained together. Training GPT-class models is, computationally, trillions of these operations — which is why the entire AI industry runs on GPUs, chips originally built to multiply matrices for 3-D graphics.
Special matrices worth knowing
- Identity : ones on the diagonal, zeros elsewhere; (does nothing).
- Transpose : flip rows and columns.
- Inverse : the "undo" matrix, (when it exists).
Key takeaways
- Matrix = data table and vector transformer; both views matter.
- A neural layer is — matrices are the weights of AI.
- Matrix multiplication composes transformations; order matters.
Check your understanding
1.A neural network layer computes . What is ?
2.Is matrix multiplication commutative ()?
3.Why do GPUs dominate AI computing?
0% of Mathematics for AI completed