Matrix Multiplication
Easy
~12 min
code completion
Matrix Multiplication
Matrix multiplication is the workhorse of ML. Nearly every layer of a neural network is a matrix multiply.
For matrices A (m×k) and B (k×n), their product C = A @ B has shape (m×n):
In NumPy:
C = A @ B # preferred C = np.matmul(A, B) # equivalent
Note: A * B is element-wise (Hadamard), not matrix multiplication.
Your task:
Implement matmul(A, B) that returns the matrix product A @ B.
Example Tests
2x2 matrix multiply
Input: {"A":[[1,2],[3,4]],"B":[[5,6],[7,8]]}
Expected: [[19,22],[43,50]]
Identity matrix multiply
Input: {"A":[[1,0],[0,1]],"B":[[3,4],[5,6]]}
Expected: [[3,4],[5,6]]
Row vector times column vector (inner product)
Input: {"A":[[1,2,3]],"B":[[1],[2],[3]]}
Expected: [[14]]