Skip to content
C

Problem 3: Matrix Multiplication Checker

Easypython

Problem Description

Write a Python program that takes two matrices and first checks whether matrix multiplication between them is valid (based on shape compatibility). If valid, compute and print the result; if not, print a clear error message.

Input

Two matrices (as nested lists), representing matrix A and matrix B.

Output

Either the resulting matrix product, or a message stating the multiplication is not possible.

Constraints

  • Matrices can be of any reasonable size, but shapes must be checked before multiplying.

Example Input

text
matrix_a = [[1,2],[3,4]], matrix_b = [[5,6],[7,8]]

Example Output

text
Result: [[19 22] [43 50]]

Concepts Covered

Matrix shapes, np.matmul(), conditional shape checking.

Input (stdin)

Output

Run your code to see output here...