Module 7: Orthogonality
The dot product is the simplest way to combine two vectors into a single number. That number carries rich geometric meaning.
For two vectors a = [a₁, a₂] and b = [b₁, b₂]:
Multiply corresponding components, add them up. That's it.
There's a second formula that reveals what the dot product is measuring:
where θ is the angle between the vectors. So the dot product is proportional to the cosine of the angle between them.
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.
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.
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.6a = [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.