Summing of Two Matrices in Theory
And Sample Python Application

18 August 2023

Back

Let A and B be two mxn matrices.

$$A: = {\left( {\matrix{ {{a_{11}}} & \cdots & {{a_{1n}}} \cr \vdots & \ddots & \vdots \cr {{a_{m1}}} & \cdots & {{a_{mn}}} \cr } } \right)_{mxn}}{\rm{ B}}: = {\left( {\matrix{ {{b_{11}}} & \cdots & {{b_{1n}}} \cr \vdots & \ddots & \vdots \cr {{b_{m1}}} & \cdots & {{b_{mn}}} \cr } } \right)_{mxn}}$$

Sum of the two matrices can be shown as:

$$A + B = {\left( {\matrix{ {{a_{11}} + {b_{11}}} & \cdots & {{a_{1n}} + {b_{1n}}} \cr \vdots & \ddots & \vdots \cr {{a_{1n}} + {b_{1n}}} & \cdots & {{a_{mn}} + {b_{mn}}} \cr } } \right)_{mxn}}$$

Sample Python Code:


The code represents:

$$A: = {\left[ {\matrix{ 5 & 7 & 3 \cr 4 & 5 & 9 \cr 4 & 2 & 1 \cr } } \right]_{3x3}}\;\;\;\;\;\;\;B: = {\left[ {\matrix{ 2 & 9 & 8 \cr 4 & 7 & 3 \cr 5 & 8 & 6 \cr } } \right]_{3x3}}$$

$$Result = A + B = {\left[ {\matrix{ {5 + 2} & {7 + 9} & {3 + 8} \cr {4 + 4} & {5 + 7} & {3 + 9} \cr {4 + 5} & {2 + 8} & {1 + 6} \cr } } \right]_{3x3}} = {\left[ {\matrix{ 7 & {16} & {11} \cr 8 & {12} & {12} \cr 9 & {10} & 7 \cr } } \right]_{3x3}}$$