Bring the mental model from Vector Spaces; this page will reuse it instead of restarting from zero.
Linear Algebra
Dot Product
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.

Concept Structure
Dot Product
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Dot ProductConceptual Bridge
What should feel connected as you move through this page.
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.
The next edge should feel earned: use the demo prediction here before following Norms.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
The dot product answers the question: “How much does one vector point in the direction of another?”
- If two arrows are aligned, the dot product is large and positive.
- If they’re perpendicular, it’s zero.
- If they point in opposite directions, it’s negative.
In ML, this becomes a similarity score (cosine similarity) and the core operation behind attention: queries and keys are compared using dot products.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let , with coordinates
The dot product is the coordinate-wise multiply-and-sum operation
This definition is algebraic, but it is designed to preserve geometry. The squared length of a vector is
so . If is the angle between two nonzero vectors, the same operation satisfies
You can read this as:
That ratio is cosine similarity. It removes the lengths and keeps only direction, which is why embeddings often use it as a normalized similarity score.
That immediately gives:
- Orthogonality: .
- Alignment: means the angle is acute, while means the angle is obtuse.
- Scaling: , so making one vector twice as long doubles the score.
- Projection: the component of along is
The scalar says how many copies of fit inside the part of that points along . The leftover
is perpendicular to , because
In attention, this same operation appears as : a query vector receives a larger score when it points in a similar direction to a key vector.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
u = np.array([2.0, 1.0])
v = np.array([-1.0, 2.0])
dot = float(u @ v)
nu = float(np.linalg.norm(u))
nv = float(np.linalg.norm(v))
cos = dot / (nu * nv)
proj_u_on_v = (dot / float(v @ v)) * v
print("u·v =", dot)
print("cos(theta) =", cos)
print("proj_v(u) =", proj_u_on_v)
print("perp component =", u - proj_u_on_v)
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Drag and , then predict whether the signed projection of along points with , nearly vanishes, or points against . Reveal after committing to connect that signed projection with the signs of and .
Live Concept Demo
Explore Dot Product
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Dot Product should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Dot Product should make visible.
Visual Inquiry
Make the image answer a mathematical question
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.
Which visible object should carry the first intuition?
Pick the cue that should make Dot Product easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Grounds inner products, vector geometry, and the linear algebra notation reused across attention and optimization.
Open sourceClaim Review
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.
Claims without a substantive review badge still need exact source-support review.
deisenroth-2020-mml
Use equation, code, and demo objects to check whether the source support is operational.
MML introduces inner products as algebraic operations with induced norms, angles, orthogonality, and projections; the page's formulas and demo instantiate those relationships in 2D and connect normalized dot products to ML similarity.
Sources: Mathematics for Machine LearningApplies to finite-dimensional real vectors with v != 0, and to angle/cosine only when both vectors are nonzero. Dot-product magnitude still includes vector lengths; cosine normalizes direction only. Excludes complex, indefinite, kernelized, or attention-scaled variants.A bounded review summary is present; still check caveats and exact source scope.MML substantively supports the claim: it defines the R^n dot product as x^T y=sum_i x_i y_i, uses inner products to induce norms/angles/orthogonality, defines cos omega=<x,y>/(||x||||y||), and derives projection onto span(b) as (<x,b>/<b,b>)b. With the dot product this is proj_v(u)=(u dot v)/(v dot v)v; local math/code/demo match.
Reviewer: codex+oracle; reviewed 2026-05-07Practice Loop
Try the idea before it explains itself
The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.
Before touching the demo, predict one visible change that should happen in Dot Product.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Dot Product
What is the smallest example that makes Dot Product click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:linear-algebra/dot-product.
- Source ids to inspect: deisenroth-2020-mml
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Dot Product Object key: concept:linear-algebra/dot-product Context: Linear Algebra Anchor id: concept/concept-notebook/linear-algebra/dot-product Open question: What is the smallest example that makes Dot Product click without losing the math? Evidence to inspect: - Source ids to inspect: deisenroth-2020-mml - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/linear-algebra/dot-product
concept:linear-algebra/dot-product