Home / Linear Algebra

Vectors and the Dot Product

Drag two vectors around the plane and watch their dot product change. This one number — the most-used operation in machine learning — tells you how much two directions agree.

Controls

a₁
a₂
b₁
b₂

Presets

Tip: you can also drag the arrowheads directly on the plot.

Vector Space

drag the arrowheads

Live Calculation

|a|
0
|b|
0
angle θ
0°
a · b
0

Overview

Compute the dot product

For equal-length vectors, the dot product multiplies matching components and sums the results:

a · b = Σᵢ aᵢbᵢ = ‖a‖‖b‖ cos θ

With a = (3, 4) and b = (1, 2), the component calculation is 3·1 + 4·2 = 11. The geometric formula explains why the sign matters: for nonzero vectors, a positive result means an angle below 90°, zero means perpendicular, and a negative result means an angle above 90°.

Vectors and the Dot Product

Multiply corresponding components and add to measure alignment, projection, or a neuron's weighted input.

Separate direction from length

A raw dot product depends on both angle and vector lengths. Cosine similarity divides by both lengths, leaving only the cosine of the angle. For unit vectors, dot product and cosine similarity are equal. A zero vector has no direction, so its cosine similarity is undefined.

That distinction matters for embeddings: normalised vectors compare direction, while unnormalised dot products also reward magnitude. A neuron computes a related expression, w · x + b. Matrix multiplication is a collection of row–column dot products; see matrix multiplication and vector norms.

Projection is a dot product too

The scalar projection of b onto a is (a · b)/‖a‖. It is the signed length of b along a; multiply by the unit direction a/‖a‖ to get the projection vector. If a is zero, this projection is undefined.

Interpret the value, not just the arithmetic

For a=(3,4) and b=(1,2), the dot product is 11. Their lengths are 5 and √5, so cos θ=11/(5√5)≈0.984: the vectors point in similar directions. If the dot product is zero and neither vector is zero, they are perpendicular. Scaling either vector scales the dot product, so comparing raw dot products across unequal lengths can be misleading. Normalise first when direction alone is the question.

The scalar projection of b onto a is (a·b)/‖a‖; the projected vector is that scalar times the unit vector a/‖a‖. This signed length is negative when b points partly opposite a. A weighted sum such as w·x is also a dot product, but it is not automatically a similarity score: the weights define what counts as a useful direction. In data applications, feature scaling and embedding normalisation affect its meaning. See vector norms for lengths and projections for the closest-point interpretation.

Try this above

Rotate one vector through a right angle. The dot product should pass through zero, change sign, and reach its largest magnitude when the vectors align or oppose.

The dot product is bilinear: a·(b+c)=a·b+a·c and (ca)·b=c(a·b). These rules let a matrix-vector product be interpreted row by row as dot products. They also make the dot product a way to test orthogonality: a·b=0 means perpendicular in the usual Euclidean geometry, including cases where one vector is zero. If a=0, the algebraic dot product is defined but the angle and cosine similarity are not, because a zero vector has no direction.

Sources and next steps

Predict, then reveal

About to run: double a₁ to 8. Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Check yourself

0 of 3

Answer without scrolling back up.

  1. Two vectors point in exactly opposite directions. Their dot product is:

  2. What does a dot product of zero tell you?

  3. Where does the dot product show up in a neural network?

Cheat sheet

Vectors and the Dot Product

Multiply matching components and sum to get a number that measures how much two vectors point the same way — behind every forward pass.

MATHS · vizlearn.in/maths/vectors_and_dot_product.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.