The matrix multiplication tensor
Matrix multiplication tensor — a fixed array of 0s and 1s that is the rule for multiplying matrices. Spanish: tensor de la multiplicación de matrices.
Number the entries of a 2 × 2 matrix row by row (11, 12, 21, 22 → 0, 1, 2, 3) and give the grid one axis for A, one for B and one for C. Cell T[a, b, c] holds a 1 exactly when entry a of A times entry b of B is added into entry c of C. For 2 × 2 that is 4 × 4 × 4: 64 cells, eight of them 1.
product = np.einsum("abc,a,b->c", T, A.ravel(), B.ravel())
# [[1, 2], [3, 4]] times [[5, 6], [7, 8]] -> 19, 22, 43, 50
The tensor holds no data. It is the rule; A and B arrive at contraction time as two vectors.