Compatibility and shape
- Input
- (2×3) × (3×2)
- Expected output
- 2×2: [[58,64],[139,154]]
C's columns (3) match D's rows (3); the result inherits C's 2 rows and D's 2 columns.
matrix multiplication
Multiplying A×B is only possible when the number of A's columns equals the number of B's rows; the result inherits A's rows and B's columns. Each entry in the resulting matrix is the sum of products between one row of A and one column of B, the same pattern repeated row by column until the whole output matrix is filled.
C's columns (3) match D's rows (3); the result inherits C's 2 rows and D's 2 columns.
The same pair of matrices, in reverse order, produces a 3×3 matrix instead of 2×2: shape and values change together.
Same two matrices, same 2×2 dimension both ways, but no entry matches between A×B and B×A.
When the number of columns of the first (A) equals the number of rows of the second (B). The result has A's rows and B's columns. Matrix multiplication is not commutative: A×B ≠ B×A in general.
No: the number of columns in the first matrix must equal the number of rows in the second. A 2×3 matrix can only multiply by another that starts with 3 rows, like a 3×2 or a 3×5; trying 2×3 times 2×2, for example, fails because 3 (A's columns) differs from 2 (B's rows).
No. With A=[[1,2],[3,4]] and B=[[5,6],[7,8]], A×B=[[19,22],[43,50]] and B×A=[[23,34],[31,46]], two completely different matrices computed from the same two factors, just by swapping the order.
O(n³) with the naive algorithm this tool uses: each of the n² entries in the result sums n products, so the total number of multiplications grows with the cube of n. Algorithms like Strassen's lower that exponent to about 2.807, at the cost of a more complex implementation.
Calculations run in your browser. No data is sent to a server.