In this **python tutorial**, you will learn **how to Multiply Two Matrices Using Multi-dimensional Arrays** with for loop of the python programming language.

## How to Multiply Two Matrices Using Multi-dimensional Arrays?

Letâ€™s take a look at the source code,Â here the values are assigned in the code, the for loop carry out the function.

RUN CODE SNIPPET# Python Program to Multiply Two Matrices Using Multi-dimensional Arrays X = [[12,7,3], [4 ,5,6], [7 ,8,9]] Y = [[5,8,1,2], [6,7,3,0], [4,5,9,1]] result = [[0,0,0,0], [0,0,0,0], [0,0,0,0]] for i in range(len(X)): for j in range(len(Y[0])): for k in range(len(Y)): result[i][j] += X[i][k] * Y[k][j] for r in result: print(r)

**OUTPUT:**

[114, 160, 60, 27] [74, 97, 73, 14] [119, 157, 112, 23]

- At first, we enter the values of three matrices. The first one with 3 rows and 3 columns and assign that matrix to the variable
`X`

. The second one with 3 rows and 4 columns and assign that matrix to the variable Â`Y`

. - The third one with 3 rows and 4 columns, which is a null matrix and assign that matrix to the variable Â
`result`

. The values are enclosed within square brackets and closed on the whole with the same. - Â We declare a
`for`

loop where the`range`

for the variable`i`

is`(len(X))`

after which we declare another`for`

loop where the`range`

for the variable`j`

is`(len(Y[0]))`

- We declare a
`for`

loop where the`range`

for the variable`k`

is`(len(Y))`

for which we give the condition`[i][j] += X[i][k] * Y[k][j]`

- We declare the finalÂ
`for`

loop where the`result`

is the variable`r`

after which we give a`print`

function which will display the values stored in the variable`r`

- In the above code we have used the
`for`

loops to iterate through each row and each column. We get the sum of products in the result.

**NOTE:**

- TheÂ
**print**Â function is used to display the value, it prints the specified message to the screen - Â The
**Â For loops**Â are used to loop through an iterable object and perform the same action for each entry. - TheÂ
**len()Â**is a built function Â used to calculate the length of any iterable object - The
**A****ddition assignment operator ( += )**Â adds the value of the right operand to a variable and assigns the result to the variable.