Skip to content
Glacius
Linear algebraConcept reference

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
  1. Overview
  2. One score from several features
  3. Read the sum
  4. Keep feature meanings aligned
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

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 x=(2,1)x=(2,1) and weights w=(3,−2)w=(3,-2), the first contribution is 3×2=63\times2=6. The second is −2×1=−2-2\times1=-2. Adding gives a score of 44. The negative weight reduces the score.

The multiplication happens coordinate by coordinate; the addition combines those contributions. With u=(2,−1)u=(2,-1) and v=(3,4)v=(3,4), a positive contribution of 66 and a negative contribution of −4-4 leave 22.

For u=(2,−1) and v=(3,4), matching products are 6 and −4. Bars share a zero baseline and signed scale. Their sum, the dot product, is 2.For u=(2,−1) and v=(3,4), matching products are 6 and −4. Bars share a zero baseline and signed scale. Their sum, the dot product, is 2.
Figure 1For u=(2,−1) and v=(3,4), matching products are 6 and −4. Bars share a zero baseline and signed scale. Their sum, the dot product, is 2.
Link to this figure ↗Download SVGDownload PNG

02Read the sum#

For u=(1,−2,3)u=(1,-2,3) and v=(4,1,2)v=(4,1,2), the three matching products are 4,−2,64,-2,6. Every position contributes once.

u⋅v=4−2+6=8u\cdot v=4-2+6=8

For equal-length vectors with dd entries, the compact notation is u⋅v=∑j=1dujvju\cdot v=\sum_{j=1}^{d}u_jv_j. The index jj names a matching position, not a separate vector. Column-vector notation writes the same scalar as uTvu^Tv.

Check your reasoning

Compute (3,−2)⋅(2,1)(3,-2)\cdot(2,1).

Show answer and explanation
4

Multiply matching entries and add: 3(2)−2(1)=43(2)-2(1)=4.

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.

Check your reasoning

For (1,2)⋅(3,4)(1,2)\cdot(3,4), the products are 3 and 8. Finish the dot product.

  1. A(3,8)(3,8)
  2. B1111
  3. C2424
Show answer and explanation
1111

Add the products: 3+8=113+8=11.

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 xjx_j increases by Δ\Delta, only one contribution changes: the score increases by wjΔw_j\Delta. A zero weight makes that feature irrelevant to this particular score. This follows directly from the weighted sum.

Check your reasoning

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
4

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.

Key takeaway

Multiply matching coordinates, then add every product into one scalar.

  • Compute the dot product of two equal-length vectors.

Sources & further reading

  1. [1]
  2. [2]
  3. [3]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Dot products.” Math behind ML. /learn/la-dot