Dot Product: Matrix × Matrix

Basics

When you have a batch of samples, each sample needs its own layer output. That's a matrix × matrix multiply: each row of X dots with each column of W^T. Here we compute it with a triple loop, then show how np.dot replaces all of it. • A's columns must equal B's rows. • Not commutative: np.dot(A, B) ≠ np.dot(B, A).

X is (3 samples × 3 features), W is (3 neurons × 3 features). X · W^T produces a (3 × 3) output where each row is one sample's neuron outputs, then we add bias b to each row.

Python
Shift+Enter to run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Step 0 / 0
Speed

Write Python code and press Shift+Enter or click "Run" to visualize.

Run the operation to see step-by-step explanation.