Explore Library
Code QuizIntermediate

Matrix Multiplication Shape Check

Find the wrong dimension comparison in this compatibility check.

Codepython
def can_multiply(A, B):
    # A is (rows_A x cols_A), B is (rows_B x cols_B)
    rows_A, cols_A = len(A), len(A[0])
    rows_B, cols_B = len(B), len(B[0])
    return cols_A == cols_B

print(can_multiply([[1, 2, 3]], [[1], [2], [3]]))  # expected True

What is the bug in this shape compatibility check?