PIXELBANKv8.2.1
Menu

Matrix Multiplication

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 AA of size m×nm \times n and BB of size n×pn \times p, the product C=A×BC = A \times B is an m×pm \times p matrix.

  1. Initialize the result matrix CC with zeros.
  2. For each element CijC_{ij}, compute the dot product of row ii from AA and column jj from BB. The resulting matrix CC represents the composition of the transformations represented by AA and BB.
Cij=k=1nAikBkjC_{ij} = \sum_{k=1}^{n} A_{ik} \cdot B_{kj}

This technique is widely used in image processing and machine learning applications.

Example:

Input:
A = [[1, 2], [3, 4]]
B = [[5, 6], [7, 8]]
Output:
[[19, 22], [43, 50]]
Reasoning:

Step-by-step calculation using the matrix multiplication formula:

Cij=k=1nAik×BkjC_{ij} = \sum_{k=1}^{n} A_{ik} \times B_{kj}

Matrix AA (2×2) × Matrix BB (2×2) = Result CC (2×2)

  1. C00C_{00}: Row 0 of AA · Column 0 of BB [1,2][5,7]=(1×5)+(2×7)=5+14=19[1, 2] \cdot [5, 7] = (1 \times 5) + (2 \times 7) = 5 + 14 = 19

  2. C01C_{01}: Row 0 of AA · Column 1 of BB [1,2][6,8]=(1×6)+(2×8)=6+16=22[1, 2] \cdot [6, 8] = (1 \times 6) + (2 \times 8) = 6 + 16 = 22

  3. C10C_{10}: Row 1 of AA · Column 0 of BB [3,4][5,7]=(3×5)+(4×7)=15+28=43[3, 4] \cdot [5, 7] = (3 \times 5) + (4 \times 7) = 15 + 28 = 43

  4. C11C_{11}: Row 1 of AA · Column 1 of BB [3,4][6,8]=(3×6)+(4×8)=18+32=50[3, 4] \cdot [6, 8] = (3 \times 6) + (4 \times 8) = 18 + 32 = 50

  5. Final result: C=(19224350)C = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}

Constraints:

  • Matrix A has dimensions m×n, Matrix B has dimensions n×p
  • 1 ≤ m, n, p ≤ 100
  • Elements are floating-point numbers
  • Round each element of the result to 4 decimal places
Editor

Test Results

0/0
Run code to see test results.