Implement matrix multiplication for two matrices A and B. This operation is crucial in linear algebra and computer vision, as it represents the composition of linear transformations.
Given matrices A of size m×n and B of size n×p, the product C=A×B is an m×p matrix.
This technique is widely used in image processing and machine learning applications.
A = [[1, 2], [3, 4]] B = [[5, 6], [7, 8]]
[[19, 22], [43, 50]]
Step-by-step calculation using the matrix multiplication formula:
Cij=∑k=1nAik×Bkj
Matrix A (2×2) × Matrix B (2×2) = Result C (2×2)
C00: Row 0 of A · Column 0 of B [1,2]⋅[5,7]=(1×5)+(2×7)=5+14=19
C01: Row 0 of A · Column 1 of B [1,2]⋅[6,8]=(1×6)+(2×8)=6+16=22
C10: Row 1 of A · Column 0 of B [3,4]⋅[5,7]=(3×5)+(4×7)=15+28=43
C11: Row 1 of A · Column 1 of B [3,4]⋅[6,8]=(3×6)+(4×8)=18+32=50
Final result: C=(19432250)