How does matrix addition work when the two matrices have different dimensions?

E.g. a 3x2 matrix + a 2x3 matrix? or a 4x2 matrix + a 5x3 matrix?

I asked because in the ML intro to mathematics with Numpy we seem to add two matrices with different dimensions, but as far as I know, that is not actually possible?

Hi Grace1, You asked an excellent question.
All these additions and multiplication in NumPy are made through a mechanism called broadcasting(Expanding rows and columns based on the last row/column of the matrix).
But these arithmetic operations work in some scenarios. Look at the image below.
Screenshot 2022-06-30 at 5.03.15 PM

In scenarios 1, 2, and 3, arithmetic operations are possible when we need to add columns or rows on just one side, and it gives an error when we need to add rows and columns on both the sides) like in scenario 4.