Last Updated On By Anmol Lohana

**Python Matrix multiplication** is an operation that takes two **matrices** and multiplies them. Multiplication of two matrices is possible when the first matrix’s rows are equal to the second matrix columns. It multiplies the row items of the first matrix with the column items of the second matrix. The **syntax** for a matrix can be as an array inside an array.

Table of Contents

There are three ways of doing matrix multiplication.

- Using For Loop
- with ListÂ
- and NumPy Library

```
matrix1 = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]
matrix2 = [[9,8,7],
[6,5,4],
[3,2,1]]
result = [[0 for x in range(3)] for y in range(3)]
# explicit for loops
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
# resulted matrix
result[i][j] += matrix1[i][k] * matrix2[k][j]
print("Resultant Matrix : ", result)
```

```
Matrix1 = [[1, 2, 3],
[4,5,6],
[7,8,9]]
Matrix2 = [[9,8,7],
[6,5,4],
[3,2,1]]
RM = [[0,0,0],
[0,0,0],
[0,0,0]]
matrix_length = len(Matrix1)
for i in range(len(Matrix1)):
for k in range(len(Matrix2)):
RM[i][k] = Matrix1[i][k] * Matrix2[i][k]
print("Multiplication of two matrices using list comprehension: ", RM)
```

**NumPy** is also known as vectorization. Using this module to reduce explicit use of for loops in the program makes program execution faster. NumPy is a built-in package of Python which is used for array processing and manipulation. We need to import NumPy in the program and use dot operator for matrix multiplication to use this package. Let’s have a look at an example.

```
import NumPy as np
matrix1 = ([1, 2, 3],[4 ,5, 6],[7, 8, 9])
matrix2 = ([9, 8, 7],[6, 5, 4],[3,2, 1])
result = np.dot(matrix1,matrix2)
print("Matrix Multiplication Using NumPy : ", result)
```

**matrix multiplication.** And coding examples in which we performed Multiplication of **3×3 matrix**