Dot products
A dot product pairs equal numbers of coordinates, multiplies corresponding entries, and sums the products into one scalar.
On this page 7 sections
01One score from several features#
A dot product combines two equal-length vectors into one number. You can use it to turn a list of features into a score: each weight says how much its matching feature contributes.
For features and weights , the first contribution is . The second is . Adding gives a score of . The negative weight reduces the score.
The multiplication happens coordinate by coordinate; the addition combines those contributions. With and , a positive contribution of and a negative contribution of leave .
02Read the sum#
For and , the three matching products are . Every position contributes once.
For equal-length vectors with entries, the compact notation is . The index names a matching position, not a separate vector. Column-vector notation writes the same scalar as .
Compute .
Show answer and explanation
Multiply matching entries and add: .
The result is a scalar even when there are many coordinates. Keeping the list of products gives an intermediate result; adding them finishes the dot product.
For , the products are 3 and 8. Finish the dot product.
Show answer and explanation
Add the products: .
03Keep feature meanings aligned#
Feature order matters. If a vector lists height before width, its weights must use the same order. Reordering both vectors together preserves every pairing. Reordering only one usually changes the score.
If only feature increases by , only one contribution changes: the score increases by . A zero weight makes that feature irrelevant to this particular score. This follows directly from the weighted sum.
A score weights hits by 3 and misses by −2, then adds. With 2 hits and 1 miss, what is the score?
Show answer and explanation
The contributions are 6 and −2, so the score is 4.
Both vectors must have the same length. A missing coordinate is not automatically zero. The formula defines a score; choosing useful weights is a later learning problem.
Multiply matching coordinates, then add every product into one scalar.
- Compute the dot product of two equal-length vectors.
Sources & further reading
- [1]OpenStax Calculus Volume 3: The Dot Product ↗openstax.org · Article
- [2]MIT 18.022: Lecture 2, Dot product ↗ocw.mit.edu · Article
- [3]Boyd and Vandenberghe, Introduction to Applied Linear Algebra ↗stanford.edu · Article