The Dot Product, Explained
Multiply matching entries, add them up, get one number. It measures how much two vectors agree — and it is what neural networks spend nearly all their time computing.
The dot product takes two lists of numbers and returns one number. Multiply the matching entries, add up the results, done.
It is worth learning properly for one reason: it is what neural networks spend essentially all of their time computing. Every neuron, every attention head, every embedding comparison is a dot product underneath.
The arithmetic
Written out:
Or for lists of any length:
The big Σ just means "add up all of these." The i underneath counts through the positions, 1 to n. The whole line says: walk both lists together, multiply each pair, total it up. That is the notation for a shopping bill.
Both lists must be the same length, because every entry needs a partner. That single requirement is why matrix dimensions have to line up, and why you spend so much time reshaping tensors.
What the number means
Arithmetic is one thing; intuition is another. Geometrically, the dot product measures how much two vectors agree.
The formula that connects the two views:
The double bars mean "length of". So: multiply the two lengths, then scale by how aligned they are. cos θ is 1 when the arrows point the same way, 0 at right angles, and −1 when opposed. The dot product is length times length times agreement.
So the sign alone tells you something useful:
This is why cosine similarity — the dot product with both lengths divided out, leaving only the part — is the standard way to ask whether two embeddings mean similar things. Strip out magnitude, keep direction, compare.
Why neural networks are made of this
Here is the part that makes the whole subject click.
A neuron holds a row of weights. It takes the dot product of that row with its inputs, adds a bias, and passes the result through an activation function. One number in, one number out.
A layer is several neurons doing that at once against the same inputs. Stack their weight rows into a grid and you have a matrix, and doing all those dot products simultaneously is precisely matrix multiplication:
Every entry of the output y is one dot product: one row of W against the input x. Matrix multiplication is not a new operation to learn — it is a table of dot products, computed in one go.
That is the entire reason GPUs matter. A GPU is a machine for doing enormous numbers of multiply-and-add operations in parallel, and a dot product is exactly multiply-and-add. When people say a model is "500 billion parameters," they are describing how many numbers take part in these sums.
Three places it shows up by name
- Similarity search. Embeddings are vectors; comparing them is a dot product. This is how retrieval finds the paragraph relevant to your question — see tokens and embeddings.
- Attention. A transformer decides which words to pay attention to by taking dot products between queries and keys. High score, more attention.
- Projection. "How much of vector a lies along direction b" is a dot product. That is what a layer is doing: measuring the input against each learned direction in turn.
Getting it right
A few things that bite:
- Lengths must match. Different-length vectors have no dot product. Most shape errors in deep learning code are this rule being enforced.
- It is not elementwise multiplication.
a * bin NumPy gives you a list;a @ bgives you the single dot-product number. Confusing the two is a classic silent bug. - Order does not matter for the dot product — — but it very much does for matrix multiplication.
- Magnitude leaks in. A long vector produces big dot products with everything. If you want similarity rather than raw score, normalise first.
The short version
- Multiply matching entries, add them up, get one number.
- Sign tells you agreement: positive = aligned, zero = unrelated, negative = opposed.
- — length times length times alignment.
- A neuron is one dot product. A layer is a stack of them, also known as matrix multiplication.
- Normalise before comparing, or magnitude dominates.
Related
- How LLMs work — what all these dot products add up to.
- Gradient descent, by hand — how the weights in those rows get set.
- The maths you actually need — where this sits in the short syllabus.
- Jacobian vs gradient — when one slope becomes a grid of them.