Matrix Addition#
Matrix addition is simple: add corresponding elements together.
The Basic Idea#
To add two matrices, add each element with its partner in the same position:
Element-by-Element#
More formally, if \(C = A + B\), then each element \(c_{ij}\) is:
The element in row \(i\), column \(j\) of \(C\) equals the sum of the corresponding elements from \(A\) and \(B\).
In Python#
Python Example
Add two matrices element by element
Click Run to execute the example.
Requirements#
The matrices must have the same shape. You can’t add a \(2 \times 3\) matrix to a \(3 \times 2\) matrix.
Python Example
See why shape compatibility matters
Click Run to execute the example.
Scalar Multiplication (Scaling)#
You can also multiply a matrix by a single number (a scalar). This scales every element:
In Python:
Python Example
Scale every element in a matrix
Click Run to execute the example.
Real-World Example#
Imagine you have sales data for two quarters:
Python Example
Combine quarterly sales data
Click Run to execute the example.
Properties#
Matrix addition has nice properties:
Commutative: \(A + B = B + A\)
Associative: \((A + B) + C = A + (B + C)\)
Identity: \(A + 0 = A\) (where \(0\) is a matrix of all zeros)
These work just like regular number addition.
Subtraction#
Matrix subtraction works the same way—subtract corresponding elements:
Python Example
Subtract corresponding entries
Click Run to execute the example.
Try It#
In the addition example, change one value in A and predict exactly which value in A + B will change.
Then try changing the scalar in the scaling example from 3 to -2. What happens to every entry?
Key Takeaways#
Matrix addition works element by element.
Matrix subtraction also works element by element.
Addition and subtraction require matching shapes.
Scalar multiplication scales every entry in the matrix.
Next Steps#
Addition is straightforward because it works element-by-element. But matrix Matrix Multiplication is different—and much more powerful. Let’s explore it next.