Skip to content

Dot Products: Two Vectors Become One Number

Textbook

For real vectors $v,w\in\mathbb R^d$, the dot product is $v^{\mathsf T}w=\sum_{i=1}^d v_iw_i$. Their dimensions must agree. The result is a single real number. Another notation is $\langle v,w\rangle$.

With $v=(3,-4)^{\mathsf T}$ and $w=(1,2)^{\mathsf T}$, the result is $3\cdot1+(-4)\cdot2=-5$. Negative contributions are neither discarded nor replaced by absolute values. Unlike an elementwise product, the coordinate products are then added, changing the result’s type.

Swapping the two vectors preserves the result because $v_iw_i=w_iv_i$ in each coordinate. Also, $v^{\mathsf T}v=\sum_i v_i^2\ge0$, with equality for real coordinates only when the vector is zero. A zero dot product of two different vectors does not imply either is zero; signed contributions can cancel. Matching list lengths is necessary, but a consistent coordinate order is required as well.

Definitions and further reading: Mathematics for Machine Learning.

In plain language

A dot product resembles a bill total: each item’s quantity is multiplied by its price, and the contributions are added. Positions must match, or the bill pays for an unusual assortment. Mathematical weights may be negative, like discounts or deductions, so signs are preserved. The result is one number; a remaining list means the cashier has not totaled the bill.

Example

The original illustrative vectors are $(3,-4)^{\mathsf T}$ and $(1,2)^{\mathsf T}$. The two contributions are computed and added with their signs intact.

Dot Products: Two Vectors Become One Number

First coordinate

The product of 3 and 1 contributes 3.

Step 1 of 3: First coordinate

Read all steps
  1. First coordinate

    The product of 3 and 1 contributes 3.

    State
    3 Γ— 1current3current
  2. Second coordinate

    Multiplying βˆ’4 and 2 gives contribution βˆ’8.

    State
    βˆ’4 Γ— 2currentβˆ’8current
  3. One total

    The contributions sum to βˆ’5; the result is a scalar.

    State
    3currentβˆ’8currentβˆ’5current

The first step accumulates 3; adding βˆ’8 then reduces the total to βˆ’5. Its absolute value 5 cannot replace the answer, because the sign carries information about the signed contributions. Reordering only the second vector would give $3\cdot2+(-4)\cdot1=2$, a different calculation. Both rows must preserve the same feature order throughout all steps of the dot product.

Related concepts: Elementwise products.

The original text of this free article is published under CC BY-NC-ND 4.0.

Previous / next

Previous
Coordinate Vectors: Order and Dimension
Next
Vector Norms: Choosing a Notion of Length
  • Natural Numbers: Counting Discrete Objects

    Which values count discrete objects, and why the zero convention must be stated.

    Read article
    Math
  • Integers: Counting on Both Sides of Zero

    Positive and negative integers, zero, and the limits of integer division.

    Read article
    Math
  • Rational Numbers: Ratios of Integers

    Numbers as ratios of integers: equivalent fractions and the nonzero denominator requirement.

    Read article
    Math