Card 1 / 11
The dot product of two equal-length vectors multiplies matching entries and adds them up: . It is the single most common operation in a neural network — every neuron's pre-activation is one.
a |
b |
result |
|---|---|---|
[1, 2, 3] |
[4, 5, 6] |
32 |
[2, -1] |
[3, 4] |
2 |
[1, 0] |
[0, 1] |
0 |
One summed index and nothing left over: runs over every position, so the result is a scalar, not a vector. A result of means the vectors are perpendicular.
No loop needed: in NumPy a @ b (1-D times 1-D is the dot product), in Eigen a.dot(b).
def dot(a: np.ndarray, b: np.ndarray) -> float:
"""Dot product of two equal-length vectors: sum_i a_i * b_i.
a: [D]
b: [D]
Returns a scalar float
"""
return float(a @ b)Card 2 / 11
Multiplying a matrix by a vector gives a vector with one entry per row of the matrix: — entry is the dot product of row of with . This is exactly how a single input is pushed through a dense layer.