Ch.02
Dot Product and Projection: Angle and Similarity Between Data
Math diagram by chapter
Select a chapter to see its diagram below. View the flow of intermediate math at a glance.
Plane: u, v, projection
base urotating vshadowresidual ⊥ u
Direction, cosine & values
−10+1
u·v
13.32
cos θ (direction)
0.969
|proj| / |v|
0.969
As green vector rotates, changes, and the amber shadow (projection) length, dot product, and move together. Nearer same direction → larger dot product; orthogonal → ; opposite → negative. The small circle shows only 's direction.
The dot product compresses “how aligned two vectors are” into a single number. An orthogonal projection moves one vector onto the line (or subspace) spanned by another—like a shadow. On from Ch.01, this chapter trains you to read similarity, angles, and distance in the language of dot products, and connects naturally to similarity, attention, and linear layers in ML and deep learning.
Dot Product and Orthogonal Projection: Measuring Similarity with Numbers
The dot product is the “multiply matching entries and add” rule from Ch.01 folded into one number. Geometrically it is . A projection onto a direction is the shadow vector you get after rescaling by that dot-product coefficient.
In plain words, the dot product scores how much two arrows point the same way. Same direction → large positive; perpendicular → ; opposite → negative. Think of projection as the shadow of a flashlight on a wall.
Here are the core formulas.
1. Dot product: (uses both lengths and the angle between the vectors)
2. Cosine similarity: (compare pure directional similarity when lengths differ)
3. Orthogonal projection: (the shadow of onto the line in the direction of )
4. Unit vector: The hat on usually means “focus on direction.” A unit vector is an arrow with length 1 (), so length is fixed and only which way it points matters. Then the shadow of onto can be written in one step as . The number is a single alignment score; the length of the shadow is its magnitude . (If the score is negative, the shadow points the opposite way along that line; for length we use the absolute value.)
Here and are norms (lengths). Cosine similarity divides by the product of those lengths, so magnitude cancels out and only direction remains.
These formulas may look dense, but they are just how a computer scores “how similar” two vectors are.
In deep learning, each linear layer is built from dot products between rows of weights and the input. Attention uses query–key dot products (or scores) to decide where to look. Recommendation uses dot products / cosines between user and item embeddings.
Summary: The dot product is “sum of products of components” and couples length and angle; projection is the shadow along a direction; cosine focuses on direction; projections pair with orthogonal residuals. Ch.03 matrices bundle many dot products at once.
After Ch.01’s “boxes of numbers,” this chapter is the rule that pairs boxes to make one score. That score becomes the common language for distance, angle, and similarity before matrices, eigenvalues, and optimization.
To make “similar” precise you need a measure. Dot products and cosines separate direction vs magnitude in high dimensions and tie directly to preprocessing (e.g. normalization).
Machine learning: similarity for kNN, kernels, linear/logistic terms ; outliers may show up as small dot products or large angles.
Geometry: least-squares fits as projection onto the column space; PCA / orthogonal bases; Gram–Schmidt subtracts projections to orthogonalize.
The table summarizes formulas and symbol meanings for solving problems, followed by item-by-item notes on why those definitions are set up that way. Worked examples walk through representative types step by step.
- Formula
- MeaningSum of products of matching components; result is a scalar
- Formula
- MeaningEuclidean norm (length)
- Formula
- Meaning — cosine of the angle between the vectors (exclude zero vectors)
- Formula
- MeaningProjection of onto the line spanned by
- Formula
- MeaningResidual after projection; always orthogonal to
- FormulaUnit
- Meaning; shadow length
| Formula | Meaning |
|---|---|
| Sum of products of matching components; result is a scalar | |
| Euclidean norm (length) | |
| — cosine of the angle between the vectors (exclude zero vectors) | |
| Projection of onto the line spanned by | |
| Residual after projection; always orthogonal to | |
| Unit | ; shadow length |
Notes on each row
① Multiply matching entries and add. The result is a scalar, not another vector. In this is .
② Defined as , the Euclidean length.
③ For angle between the vectors, . Keep denominators nonzero (avoid zero vectors). Same direction → near ; orthogonal → ; opposite → negative.
④ For , . Think of the shadow of on the line along .
⑤ The residual; always orthogonal to , and is an orthogonal decomposition.
⑥ Unit If , then is the projection, and is the shadow length along .
Practice problems
Below are 10 problems sampled from a bank of 60 (easy 4 · medium 3 · hard 3; order easy→medium→hard). Each item is multiple choice—pick the option number.
In logistic regression with , what does mainly encode?
1 / 10