Matrix Difference Calculator

00:00
EasyArrays2D ArrayMath

Given two 2D matrices represented as lists of lists, implement a function that returns their difference. If the matrices have different dimensions, return an empty list. The difference is calculated by subtracting each element of the second matrix from the corresponding element of the first matrix (C[i][j] = A[i][j] - B[i][j]).

Examples

Input → [[5, 2], [1, 7]], [[3, 1], [0, 4]]
Output → [[2, 1], [1, 3]]
Explanation:

Standard 2x2 matrix subtraction.

Input → [[1, 2], [3, 4]], [[1, 2]]
Output → []
Explanation:

The matrices have different row counts.

Input → [[10, 10]], [[5, 5]]
Output → [[5, 5]]
Explanation:

Testing single row matrix subtraction.