Loading...
Loading...
You are given two 2d integer lists a and b. Each element of a is a row of a matrix with a.length rows and a[0].length columns, and each element of b is a row of a matrix with b.length rows and b[0].length columns.
Return the product of the two matrices as a 2d integer list.
If the dimensions are incompatible, return [].
Definition (Product of Matrices): The entry at row i and column j of the product is the sum of a[i][k] * b[k][j] over every k from 0 to a[0].length - 1. The dimensions are incompatible if the number of columns of a is not equal to the number of rows of b.
a.length ≤60a[i].length ≤60b.length ≤60b[i].length ≤60a[i].length = a[0].length for all ib[i].length = b[0].length for all ia[i][j] ≤100b[i][j] ≤100Each entry of the product is the sum of products of a row of a and a column of b, for example the top-left entry is 1*5 + 2*7 = 19.
This is an outer product - a 3 x 1 column times a 1 x 4 row gives a 3 x 4 matrix.
a has 3 columns and b has 2 rows, so the two matrices cannot be multiplied and the result is [].
Multiplying by the identity matrix leaves b unchanged, so the result equals b.