Computing Library › Linear Algebra
Linear Algebra

The Dot Product

Multiply matching components and add; the result measures length, angle, and alignment between two vectors.

Two equivalent definitions

The dot product of vectors x and y in R^n is x . y = x1 y1 + x2 y2 + ... + xn yn, the sum of products of matching components. It also has a geometric form: x . y = |x| |y| cos(theta), where theta is the angle between the vectors. Equating the two forms is how the angle between vectors is defined and computed.

What it tells you

Kronos motion — stat triple product

Algebraic properties

The dot product is symmetric, x . y = y . x; linear in each argument; and positive definite, x . x is positive for every nonzero x. These three properties are exactly the axioms of a real inner product, so the dot product is the prototype of the more general inner products used on function spaces.

Matrix form

Written with matrices, x . y = x^T y, a 1-by-n row times an n-by-1 column giving a scalar. This links the dot product to the transpose and explains why expressions like A^T A, which are Gram matrices of dot products, appear throughout least squares and statistics.

python
import numpy as np
x = np.array([1.0, 2.0, 2.0])
y = np.array([2.0, 0.0, 1.0])
print(x @ y)                       # 4.0
cos = (x @ y) / (np.linalg.norm(x) * np.linalg.norm(y))
print(np.degrees(np.arccos(cos)))  # angle in degrees

The Cauchy-Schwarz inequality, |x . y| <= |x| |y|, bounds the dot product by the product of lengths and underlies error estimates throughout applied mathematics and signal processing.