Mathematical Foundations

dot product

/ DOT PROD-ukt /

The dot product is a way to take two lists of numbers and boil them down to a single number that says how much they agree. The recipe is simple: line up the two lists, multiply them entry by entry, then add up all those products. If one list is [3, 0, 2] and the other is [1, 4, 5], the dot product is 3×1 + 0×4 + 2×5 = 13. That one number summarizes the whole pairing.

Geometrically it measures alignment. Two vectors pointing the same way give a large positive dot product; pointing in opposite directions gives a negative one; and at a right angle (perfectly unrelated) the dot product is exactly zero. So you can read it as a similarity score: bigger means more in step, zero means perpendicular, negative means pulling apart.

This tiny operation is the atom of modern machine learning. An artificial neuron computes the dot product of its inputs with its weights, then decides how strongly to fire. Search engines and recommendation systems rank items by the dot product between a query's vector and each candidate's vector. And the matrix multiplications that power neural networks are nothing but vast batteries of dot products run in parallel. Master this one idea and a huge amount of the math stops looking mysterious.

Rate a movie on [action, romance, comedy] as [5, 1, 2], and rate your taste on the same three as [4, 0, 1]. Their dot product is 5×4 + 1×0 + 2×1 = 22 — a high score, because the movie is heavy on action and so are you. A weepy romance scored [0, 5, 0] would give just 0×4 + 5×0 + 0×1 = 0: no overlap, no match.

A recommender's heartbeat: multiply matching features, add them up, and a single number tells you how well two things line up.

A dot product needs both lists to be the same length, and it always returns a single number, never a list. Its raw size also grows with the vectors' lengths, so for a pure measure of direction people often divide it out to get cosine similarity, which lives between -1 and 1.

Also called
点积點積内积內積inner productscalar product数量积