For column vectors, ABx means apply B first, then A. Matrix multiplication is associative, (AB)C = A(BC), but usually not commutative: AB and BA can have different shapes or values. The matrix transformation lesson shows this order geometrically.
The cost of multiplying m × n by n × p is proportional to mnp for the standard algorithm. For a chain of matrices, changing the grouping can therefore change the amount of work without changing the result. Deep-learning layers use these products to transform batches of feature vectors efficiently.
In code, NumPy uses @ for matrix multiplication and * for elementwise multiplication. Check shapes explicitly when a product fails; do not transpose matrices just to silence an error without checking what operation is intended.
Calculate a small product and check its shape
Let A=[[1,2],[3,4]] and B=[[2,0],[1,5]]. The upper-left entry of AB is the first row of A dotted with the first column of B: 1·2+2·1=4. The upper-right entry is 1·0+2·5=10. Repeating this row-column calculation gives AB=[[4,10],[10,20]]. The result is 2×2 because A's rows combine B's columns. If A is m×n and B is r×p, the product AB exists only when n=r, and its output is m×p.
Matrix multiplication is associative but usually not commutative: AB and BA can differ even when both exist. This reflects composition order: for column vectors, ABx applies B first. Elementwise multiplication is a different operation, often written A*B in array libraries; it requires compatible element shapes rather than matching inner dimensions. When an operation fails, inspect whether the intended calculation is a matrix product, transpose, or elementwise operation before changing shapes. For a chain of products, parenthesisation changes computational cost but not the result.
Try this above
Change the matrix dimensions so the inner sizes match, then alter one entry and trace which output cell changes.
Associativity means a chain A(BC) and (AB)C gives the same mathematical result, but intermediate matrix sizes can differ dramatically. For example, multiplying a 100×2 matrix by a 2×1000 matrix costs much less than first multiplying the 2×1000 matrix by a 1000×1000 matrix in a larger chain. Choosing the grouping can reduce computation without changing the function. This is called matrix-chain ordering. In floating-point arithmetic, different groupings can also produce slightly different rounding, even though the exact algebra is associative.