How To Do Dot Product With Vectors
You're staring at two vectors. Maybe they're force and displacement in a physics problem. Think about it: maybe they're word embeddings in a machine learning pipeline. Maybe you're just trying to pass linear algebra and the textbook explanation left you more confused than when you started.
Here's the thing: the dot product is everywhere. And once you actually see what it's doing — not just the formula, but the geometry — it stops being mysterious.
What Is the Dot Product
At its core, the dot product takes two vectors and gives you a single number. A scalar. That's it. And no vector out the other side. Just a number.
The algebraic definition
If you have two vectors in n-dimensional space:
a = (a₁, a₂, ..., aₙ)
b = (b₁, b₂, ..., bₙ)
Their dot product is:
a · b = a₁b₁ + a₂b₂ + ... + aₙbₙ
Multiply corresponding components. Add them up. Done.
For three dimensions — the case you'll see most often in physics and graphics:
a · b = aₓbₓ + aᵧbᵧ + a_zb_z
The geometric definition
This is where it gets interesting. The same operation equals:
a · b = ‖a‖ ‖b‖ cos θ
Where ‖a‖ and ‖b‖ are the magnitudes (lengths) of the vectors, and θ is the angle between them.
Two completely different-looking formulas. Same result. That's not a coincidence — it's the bridge between algebra and geometry.
Why It Matters
The dot product tells you how much two vectors point in the same direction.
That's the intuition. Everything else follows from it.
In physics: work
Work = F · d
Force dotted with displacement. If you push a box perpendicular to its motion, you do zero work. But the dot product captures that automatically — cos 90° = 0. Push at an angle, and only the component of force along the displacement counts.
In computer graphics: lighting
The classic Lambertian shading model: brightness = n · l
Surface normal dotted with light direction. When they align, full brightness. When the light grazes the surface, the dot product drops toward zero. Negative means the light's behind the surface — backface culling territory. And it works.
In machine learning: similarity
Cosine similarity = (a · b) / (‖a‖ ‖b‖)
Strip away magnitude, keep only direction. Two documents with similar word frequency patterns? Their vectors have a high cosine similarity. This is how search engines, recommendation systems, and clustering algorithms measure "alike-ness.
In geometry: projection
The scalar projection of a onto b is exactly a · b / ‖b‖
The vector projection is (a · b / ‖b‖²) b
This shows up constantly — finding the component of a force along a ramp, decomposing velocity, collision detection in games.
How to Compute It
By hand: the component method
This is the one you'll use on exams and quick calculations.
Example: a = (3, -2, 5), b = (1, 4, -2)
a · b = (3)(1) + (-2)(4) + (5)(-2)
= 3 - 8 - 10
= -15
Negative result. On the flip side, the vectors point generally opposite directions. The angle between them is obtuse.
By hand: the geometric method
Sometimes you're given magnitudes and an angle.
Example: ‖a‖ = 4, ‖b‖ = 6, θ = 60°
a · b = (4)(6) cos 60°
= 24 × 0.5
= 12
Positive. Acute angle. They're pointing somewhat the same way.
In code: Python with NumPy
import numpy as np
a = np.array([3, -2, 5])
b = np.array([1, 4, -2])
dot = np.dot(a, b)
# or: dot = a @ b (Python 3.5+)
print(dot) # -15
In code: plain Python (no dependencies)
def dot_product(a, b):
return sum(x * y for x, y in zip(a, b))
a = [3, -2, 5]
b = [1, 4, -2]
print(dot_product(a, b)) # -15
In code: JavaScript
function dot(a, b) {
return a.reduce((sum, val, i) => sum + val * b[i], 0);
}
const a = [3, -2, 5];
const b = [1, 4, -2];
console.log(dot(a, b)); // -15
In MATLAB / Octave
a = [3, -2, 5];
b = [1, 4, -2];
dot(a, b) % returns -15
In R
a <- c(3, -2, 5)
b <- c(1, 4, -2)
sum(a * b) # -15
Common Mistakes
Confusing dot product with cross product
This is the big one. That's why dot product gives a scalar. Cross product gives a vector (in 3D and 7D only). They're fundamentally different operations.
If you found this helpful, you might also enjoy circuit diagram ammeter readings a1 a2 a3 current comparison or in a covalent bond electrons are.
Cross product: a × b = ‖a‖ ‖b‖ sin θ n
Dot product: a · b = ‖a‖ ‖b‖ cos θ
One uses sine, the other cosine. On the flip side, one gives a vector perpendicular to both inputs. The other gives a number measuring alignment.
Forgetting that
Forgetting that zero doesn't mean "nothing"
A dot product of zero means the vectors are perpendicular (orthogonal), not that they're trivial or unimportant. On top of that, in fact, orthogonality is one of the most powerful concepts in linear algebra — it's the foundation of orthogonal bases, Fourier transforms, Gram-Schmidt orthogonalization, and PCA. A zero dot product is a meaningful* result, not a failed calculation.
Forgetting the dimensions must match
You can only take the dot product of two vectors with the same number of components. On top of that, a 3D vector dotted with a 2D vector is undefined. This trips people up when working with padded data, mismatched feature vectors, or when accidentally slicing arrays incorrectly in code.
# This will raise an error or silently give wrong results
a = np.array([1, 2, 3])
b = np.array([4, 5])
np.dot(a, b) # ValueError: operands could not be broadcast together
Forgetting the dot product is commutative
a · b = b · a. The order doesn't matter. This seems obvious, but it's worth remembering when reordering terms in proofs or simplifying expressions. It's also what makes the dot product a symmetric bilinear form*.
Forgetting the connection to the law of cosines
The dot product formula is essentially the law of cosines in disguise. If you set a and b as two sides of a triangle emanating from the same origin, then ‖a − b‖² = ‖a‖² + ‖b‖² − 2(a · b), which rearranges directly to the dot product definition. This means the dot product is fundamentally a statement about triangles — it tells you the relationship between two sides and the angle between them.
Why It Matters Beyond the Math
The dot product is not just an academic exercise. It's the engine behind:
- Neural networks — every neuron computes a weighted sum (a dot product) of its inputs, then applies an activation function. The entire foundation of deep learning rests on this single operation, repeated billions of times.
- Graphics pipelines — lighting calculations (Lambertian shading), shadow mapping, and view frustum culling all rely on dot products to determine how surfaces interact with light and camera rays.
- Natural language processing — word embeddings like Word2Vec and GloVe represent words as vectors, and similarity between words is computed via dot product (or cosine similarity, which is a normalized dot product).
- Quantum mechanics — probability amplitudes are computed using inner products, a direct generalization of the dot product to complex vector spaces.
- Finance — portfolio return is the dot product of a weight vector and a return vector. Risk (variance) involves dot products of covariance matrices with weight vectors.
Wrapping Up
The dot product is one of those operations that looks simple on the surface — just multiply and add — but carries enormous depth underneath. It bridges algebra and geometry, connects magnitude to direction, and serves as the backbone of countless algorithms across disciplines.
Once you internalize what it means* — not just how to compute it — you start seeing it everywhere. Here's the thing — in the way a game engine decides which faces are visible. In the way a recommendation system finds similar users. In the way a language model understands that "king" and "queen" live in similar conceptual neighborhoods.
That's the real power of the dot product: it turns geometric intuition into computational machinery. And once you have that intuition, you're equipped to understand — and build — systems that are far more sophisticated than the simple formula suggests.
The dot product is small in code, vast in meaning.
Latest Posts
Newly Published
-
7 3 As A Whole Number
Aug 04, 2026
-
Atoms Are Created And Destroyed In Chemical Reactions
Aug 04, 2026
-
Function Of The Tongue In A Frog
Aug 04, 2026
-
How Many Bones Are In A Giraffe
Aug 04, 2026
-
Chemistry In Our Day To Day Life
Aug 04, 2026
Related Posts
A Few Steps Further
-
Which Is A Non Membrane Bound Organelle
Aug 01, 2026
-
How To Solve For Limiting Reagent
Aug 01, 2026
-
How Many Electrons In The F Orbital
Aug 01, 2026
-
Length Of Segment Of Circle Formula
Aug 01, 2026
-
What Type Of Tissue Is Avascular
Aug 01, 2026