Linear Algebra Basics
Vectors, matrices and the dot product: the arithmetic that every model, from linear regression to transformers, runs on.
Also vectors · matrices · dot product · matrix multiplication · tensors · cosine similarity
A vector is a list of numbers, like a recipe: 2 eggs, 1 cup flour, 3 spoons sugar. A matrix is a whole recipe book. Multiplying them is how a model mixes its ingredients to make a prediction.
Where it fits
+All relationships as a list
Is a kind of / part of
Siblings
Used by
How it works
You can go a long way in ML with three objects and one operation.
- A vector is a list of numbers. A house can be the vector (120 m², 3 rooms, 1995). A word embedding is a vector of a few hundred numbers.
- A matrix is a grid of numbers. A dataset is a matrix (one row per example). The weights of a neural network layer are a matrix.
- A tensor is the same idea with more axes, such as a batch of images: batch × height × width × color.
The key operation is the dot product: multiply matching entries and add them up.
It shows up everywhere:
- Linear regression predicts .
- A neuron computes a dot product, then applies an activation function.
- A layer of neurons is a matrix multiplication: many dot products at once. That is why GPUs matter.
- Attention scores are dot products between query and key vectors.
- Cosine similarity, the dot product of normalized vectors, measures how alike two embeddings are in vector databases.
Matrices also describe transformations (rotate, stretch, project). PCA finds the directions in which a data matrix stretches the most, and LoRA approximates a big matrix update by multiplying two thin ones.
Everyday use cases
- Case 01
Search by meaning
Comparing two text embeddings with a dot product (cosine similarity) finds documents about the same thing.
- Case 02
GPUs
GPUs are fast at ML because they are fast at matrix multiplication, which is most of the work.
Strengths, weaknesses and when to use it
Strengths
- A few operations explain most of what happens inside neural networks.
Weaknesses
- Abstract notation can hide simple ideas; drawing vectors as arrows helps.
When to use itBefore diving into neural networks, attention or PCA.
Check yourself
- Q01
What does a large positive dot product between two embedding vectors usually mean?
Show answer
A: They point in similar directions
- Q02
A dense neural network layer is mainly...
Show answer
B: A matrix multiplication followed by a nonlinearity