Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-142

Matrix Equality Check

Problem

Return True if matrices A and B have the same shape and all corresponding entries differ by at most 1e-9.

Otherwise return False.

Hint

Shape mismatch is an immediate False; otherwise compare entrywise with a tolerance.

Test cases

case 1
in: [[[1,2],[3,4]],[[1,2],[3,4]]]
expected: true
case 2
in: [[[1,2],[3,4]],[[1,2],[3,5]]]
expected: false
case 3
in: [[[1,2]],[[1,2],[3,4]]]
expected: false
case 4
in: [[[0.30000000000000004]],[[0.3]]]
expected: true
Starter codePython
def matrices_equal(A, B):
    # Your code here
    pass

4 test cases · run your code against them in the editor