Skip to content

Matrix Multiplication

Background

Matrix multiplication involves computing the dot product of rows from the first matrix and columns from the second. The number of columns in the first matrix must match the number of rows in the second.

Task

Write a function matrix_mul(mat1, mat2) that multiplies two matrices.

Specifications

  • The function takes two 2D lists mat1 and mat2.
  • It should return their matrix product as a new 2D list.

Constraints

  • The matrices will have compatible dimensions: $M \times N$ and $N \times P$.
  • Matrices will not be empty.

Example

>>> matrix_mul([[1, 2], [3, 4]], [[2, 0], [1, 2]])
[[4, 4], [10, 8]]

Instructions

  1. Implement the logic in solution.py.
  2. Do not use input() or print().
  3. Test your solution locally before submitting.

Solve Online | Ver en Español, | Leer en Español