Linear Algebra

Dot Product

The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.

status: publishedimportance: criticaldifficulty 2/5math: undergraduateread: 12mlive demo
Editorial mathematical illustration of two vectors, their angle, and a projection shadow.

Concept Structure

Dot Product

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
3next concepts
2related links

Learning map

Dot Product
BeforeVector SpacesNow4/4 sections readyTryManipulate one control and predict the visible change.NextNorms

Object flow

4/4 sections readyAsk about thisResearch room
ConceptDot ProductLinear Algebra
1 source attachedLocal snapshot ready
concept:linear-algebra/dot-product

Conceptual Bridge

What should feel connected as you move through this page.

Carry inVector Spaces

Bring the mental model from Vector Spaces; this page will reuse it instead of restarting from zero.

Work hereDot Product

The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.

Carry outNorms

The next edge should feel earned: use the demo prediction here before following Norms.

Test the linkManipulate one control and predict the visible change.Then continue to Norms
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

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

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let u,vRnu,v \in \mathbb{R}^n, with coordinates

u=(u1,,un),v=(v1,,vn).u = (u_1,\ldots,u_n), \qquad v = (v_1,\ldots,v_n).

The dot product is the coordinate-wise multiply-and-sum operation

uv=i=1nuivi.u \cdot v = \sum_{i=1}^n u_i v_i.

This definition is algebraic, but it is designed to preserve geometry. The squared length of a vector is

u2=uu=i=1nui2,\|u\|^2 = u \cdot u = \sum_{i=1}^n u_i^2,

so u=uu\|u\| = \sqrt{u\cdot u}. If θ\theta is the angle between two nonzero vectors, the same operation satisfies

uv=uvcosθ.u \cdot v = \|u\|\,\|v\|\cos\theta.

You can read this as:

uvuv=cosθ.\frac{u \cdot v}{\|u\|\,\|v\|} = \cos\theta.

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: uv    uv=0u \perp v \iff u\cdot v = 0.
  • Alignment: uv>0u\cdot v > 0 means the angle is acute, while uv<0u\cdot v < 0 means the angle is obtuse.
  • Scaling: (au)v=a(uv)(au)\cdot v = a(u\cdot v), so making one vector twice as long doubles the score.
  • Projection: the component of uu along vv is
projv(u)=uvvvv(v0).\operatorname{proj}_v(u) = \frac{u\cdot v}{v\cdot v} \, v \quad (v \neq 0).

The scalar uvvv\frac{u\cdot v}{v\cdot v} says how many copies of vv fit inside the part of uu that points along vv. The leftover

u=uprojv(u)u_\perp = u - \operatorname{proj}_v(u)

is perpendicular to vv, because

uv=(uuvvvv)v=uvuvvv(vv)=0.u_\perp \cdot v = \left(u - \frac{u\cdot v}{v\cdot v}v\right)\cdot v = u\cdot v - \frac{u\cdot v}{v\cdot v}(v\cdot v) = 0.

In attention, this same operation appears as qkq\cdot k: a query vector receives a larger score when it points in a similar direction to a key vector.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
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

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Drag uu and vv, then predict whether the signed projection of uu along vv points with vv, nearly vanishes, or points against vv. Reveal after committing to connect that signed projection with the signs of uvu\cdot v and cosθ\cos\theta.

Live Concept Demo

Explore Dot Product

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 2/5undergraduatecode-aligned
Demo Prediction Checkpoint

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.

Prediction open01 / Intuition
Editorial mathematical illustration of two vectors, their angle, and a projection shadow.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

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.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

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.

book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong

Grounds inner products, vector geometry, and the linear algebra notation reused across attention and optimization.

Open source

Claim Review

The dot product measures alignment: it connects angles, lengths, and projections, and underlies cosine similarity in ML.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources1 reference

deisenroth-2020-mml

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedFor vectors u,v in R^n, the dot product sum_i u_i v_i is a coordinate multiply-sum that also encodes geometry: u dot v = ||u||||v||cos(theta), so sign and size track alignment, cosine similarity removes lengths, and proj_v(u) scales v by (u dot v)/(v dot v).Claim metadata: source checked

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-07

Practice 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.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Dot Product.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptDot ProductLinear Algebra
Code witness comparisonDot Product code witness 1u = np.array([2.0, 1.0])Prediction before revealDot Product interactive demoManipulate one control and predict the visible change.
Grounded room questionWhat is the smallest example that makes Dot Product click without losing the math?Local snapshot ready

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.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptLinear Algebra

Dot Product

Anchored question

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
Local action draft

This draft stays locally in this browser for concept:linear-algebra/dot-product.

No local draft saved.
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
Grounded AI handoff

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.

Open source object
concept/concept-notebook/linear-algebra/dot-product concept:linear-algebra/dot-product