### WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

*4) Matrices Multiplication*
Two matrices (

**A** and

**B**) can be multiplied if they are compatible, meaning that the first (left) matrix has as many columns as the second (right) matrix has rows. If matrices

**A** and

**B** meet this condition, you can multiply them. The result of such a multiplication will be matrix

**C**, which has as many rows as matrix

**A** and as many columns as matrix

**B**:

```
```**A**_{mxn} ∙B_{nxp} = C_{mxp}

The rules for matrices multiplication are not as trivial as for scalar matrix multiplication. To calculate the **ij-element** of the product matrix, you need to multiply the **i**^{th} row vector of the first matrix by the **j**^{th} column vector of the second matrix. The multiplication of a row vector by a column vector goes as follows:

1. Multiply the first elements of the row and column vectors to get product 1.

2. Multiply the second elements of the row and column vectors to get product 2.

. . . . . . . . . . . . .

N. Multiply the Ns elements of the row and column vectors to get product N.

Lastly, sum up all the products.

The result of such a calculation will be a scalar.

Figure 2 shows the algorithm in math notation for **A**_{mxn} ∙B_{nxp} = C_{mxp} (where i = 1, 2, . . m, and j =1, 2, . . p.).

**Figure 2. Calculating ij-element of Product Matrix C**: Here is the algorithm in math notation for **A**_{mxn} ∙B_{nxp} = C_{mxp}. |

To find product **C = A ∙ B**, where:

You would use this solution:

Matrices multiplication is not commutative (i.e., **A∙B ≠ B∙A**). Indeed, in Example 4, the multiplication **A**_{3x2} ∙ B_{2x4} is allowed, because matrices **A**_{3x2} and **B**_{2x4} are compatible. However, the multiplication **B**_{2x4} ∙ A_{3x2} would be illegal, because the number of columns in the left matrix is not equal to the number of rows in the right matrix. But even if both **A∙B** and **B∙A** are compatible, that doesn’t guarantee the same result.

Consider two square matrices:

However, matrices multiplication is associative and distributive:

- associative -
**A∙(B∙C) = (A∙B)∙C**
- distributive -
**A∙(B + C) = A∙B + A∙C**
- distributive -
** (A + B)C = A∙C + B∙C**

*5) Matrix Transpose*

The transposing of a matrix simply means an exchange between the rows and the columns. Suppose you have an **m x n** matrix, **A**_{mxn}. If you transpose that matrix, you will get an **n x m** matrix, **B**_{nxm}, with the following correspondence between the elements of **A** and **B**:

```
```**a**_{ixj} = b_{jxi}, for all **i** and **j**.

The most common notation for the transposing of matrix **A** is **A**^{T}.

Find the transpose of a matrix **A** as follows: