The Dot Product
Multiply and sum.
The dot product of two vectors is simple. Multiply them position by position, then add everything up. It turns two vectors into a single number. And it's at the heart of almost every machine learning model.

- Multiply position by position
- Add it all up
- One number
A prediction is a dot product
Here's a house, and a set of weights, one for each feature. The dot product multiplies size by its weight, rooms by its weight, and age by its weight, then adds them. Run it. That's exactly how a linear model makes a prediction. The at sign is Python's shortcut for it.
import numpy as np
house = np.array([120, 4, 10])
weights = np.array([2.0, 10.0, -1.5])
print("by hand:", (house * weights).sum())
print("np.dot: ", np.dot(house, weights))
print("@: ", house @ weights)by hand: 265.0 np.dot: 265.0 @: 265.0
What the dot product measures
Besides making predictions, the dot product measures how much two vectors point the same way. It's large and positive when they point in similar directions, zero when they're at right angles, and negative when they point in opposite directions. Neural networks are, at heart, millions of dot products.
| key | value |
|---|---|
| Formula | Σ aᵢ × bᵢ |
| Positive | similar direction |
| Zero | at right angles |
| Negative | opposite directions |
Summary
The dot product multiplies and sums, turning two vectors into one number. Linear models and neural networks are built on it. Next, the length of a vector.
Key takeaways- np.dot or @
- Prediction = features · weights
- Measures alignment