Matrix Multiplication

Matrix multiplication is the operation that lets one linear map follow another. In data science it also computes many dot products at once: scores, projections, attention logits, and neural-network layer outputs are all variations on .

Defining math

If and , then

The inner dimensions must match because each output entry is a dot product between one row of and one column of . Multiplication is associative, , but usually not commutative: . As a composition rule, applying then gives .

This is why gradients in linear models contain terms like and why backpropagation is full of matrix products and transposes. Jacobians and Hessians generalize the same composition idea to derivatives.

Worked example

Take

Each entry of is one row of dotted with one column of . Writing every entry as its row-by-column sum,

The first row, second column is . Reading as two examples and as two coefficient vectors, produces two scores for each example.

Caveats

The order of multiplication encodes meaning. and may both be valid in some dimensions but represent different maps. Large products can also be dominated by conditioning and scale; those issues connect to numerical stability, not to the algebraic definition alone.

References