<aside> <img src="/icons/list_gray.svg" alt="/icons/list_gray.svg" width="40px" />

목차

</aside>

Definition


image.png

If here are $A$ ($m \times n$) matrix and $B$ ($n\times p$) matrix, then their product $AB$ makes $C$ ($m \times p$ ) matrix.

<aside> <img src="/icons/question-mark_blue.svg" alt="/icons/question-mark_blue.svg" width="40px" />

Conditions for Matrix multiplication

image.png

The number of columns in $A$ must equal the number of rows in $B$.

Formula

$$ A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \\ a_{31} & a_{32} \end{bmatrix}

$$

$$ B = \begin{bmatrix} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \\

\end{bmatrix}

$$

$$ C = AB = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \\ a_{31} & a_{32} \end{bmatrix} \times \begin{bmatrix} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \\ \end{bmatrix} $$

image.png

Each element $c_{ij}$ of $C$ is calculated as the dot product of the $i$th row in $A$ and the $j$th column in $B$.

Practice with Python

A = np.array([[1,2,3],
              [4,5,6]])

B = np.array([[1,2],
              [4,5],
              [7,8]])

print(A@B)

When executed, this code will output like that.

# AB
[[30 36]
 [66 81]]

Properties


Non-Commutativity

It’s also a simple rule.

$$ AB \neq BA $$

For example, Here is $A$ = $2\times 3$ matrix, $B$ = $3\times 2$ matrix.

Associativity

$$ (AB)C = A(BC) $$

This means that when multiplying several matrices, the placement of parentheses doesn’t affect the result.

Distributivity

$$ A(B+C) = AB + AC $$

This holds when $A$ = $m \times n$ matrix, $B$, $C$ = $n \times p$ matrices.

A = np.array([[1,2,3],
              [4,5,6],
              [7,8,9]])

B = np.array([[5,1],
              [1,7],
              [9,3]])

C = np.array([[4,6],
              [7,3],
              [1,5]])

print(A@(B+C))
print(A@B + A@C)

print(A@(B+C) == A@B + A@C)

You can check outputs about distributivity.

# A(B+C)
[[ 55  51]
 [136 126]
 [217 201]]

# AB + AC
[[ 55  51]
 [136 126]
 [217 201]]
 
# Consistency!
[[ True  True]
 [ True  True]
 [ True  True]]

Row Vector-Matrix Multiplication


The product($uA$) of row vector $u$, matrix $A$ is a linear combination of the row vectors of $A$.

Formula

$$ u = [u_1, u_2, u_3] $$

$$ A = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} $$

$$ uA = [u_1, u_2, u_3] \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = [v_1, v_2, v_3] $$

Practice with Python

A = np.array([[1,2,3],
              [4,5,6],
              [7,8,9]])
              
u = np.array([3,4,5])

print(A@u)

You can get the output like that.

[54 66 78]

Matrix-Column Vector Multiplication


The product($Ax$) of matrix $A$, column x is a linear combination of the column vectors of $A$.

Formula

$$ A = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} $$

$$ x = \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} $$

Practice with Python

A = np.array([[1,2,3],
              [4,5,6],
              [7,8,9]])

x = np.array([[3],
              [4],
              [5]])

print(A@x)

You can check output like below.

[[26]
 [62]
 [98]]