determin.ant
07-orthogonality / 7.1

Module 7: Orthogonality

Dot Product

Where you'll see this: dot products are the engine of neural networks — every neuron computes a weighted sum, which is a dot product. Cosine similarity (used in search engines and recommendation systems) is a normalized dot product. It measures how "aligned" two things are.

The dot product is the simplest way to combine two vectors into a single number. That number carries rich geometric meaning.

The formula

For two vectors a = [a₁, a₂] and b = [b₁, b₂]:

ab=a1b1+a2b2\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2

Multiply corresponding components, add them up. That's it.

The geometric interpretation

There's a second formula that reveals what the dot product is measuring:

ab=abcosθ\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}|\,|\mathbf{b}|\cos\theta

where θ is the angle between the vectors. So the dot product is proportional to the cosine of the angle between them.

Three cases:
θ = 0° (pointing the same way) → a·b = |a||b| (maximum positive)
θ = 90° (perpendicular) → a·b = 0
θ = 180° (pointing opposite ways) → a·b = −|a||b| (maximum negative)

Orthogonality

Two vectors are orthogonal (perpendicular) if and only if their dot product is zero. This is the foundation of Module 7 — we'll use it to build coordinate systems, projections, and least squares.

Try it

Drag the blue and pink vectors. Watch the dot product and angle update. Try to make the dot product zero — the vectors will be at exactly 90° and you'll see the right-angle mark appear.

In NumPy — three equivalent ways:
import numpy as np
a = np.array([3, 1])
b = np.array([1, 3])

print(np.dot(a, b))       # 6  — standard
print(a @ b)              # 6  — matrix multiply notation
print(sum(a * b))         # 6  — manual

# Cosine similarity
cos_sim = np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(cos_sim)  # 0.6
Markov ChainsProjection
-6-6-5-5-4-4-3-3-2-2-1-1112233445566ab

a = [3, 1] |a| = 3.16

b = [1, 3] |b| = 3.16

a · b = 6

angle = 53° · · |a||b|cos θ = 10 × 0.6 = 6

Drag the vectors. When they're perpendicular, a·b = 0.