Python Program to find Matrix Multiplication
You are Here:
Find Matrix Multiplication
In the following example, we will multiply the two given matrices (two-dimensional arrays).
Example
Python Compiler
arr1 = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
arr2 = [
[2, 2, 2],
[2, 2, 2],
[2, 2, 2]
]
arr3 = [[0]*3 for _ in range(3)]
print("Matrix A (3 x 3):")
for i in range(0, 3):
for j in range(0, 3):
print(arr1[i][j], end=" ")
print()
print("\nMatrix B (3 x 3):")
for i in range(0, 3):
for j in range(0, 3):
print(arr2[i][j], end=" ")
print()
for i in range(0, 3):
for j in range(0, 3):
for k in range(0, 3):
arr3[i][j] = arr3[i][j] + arr1[i][k] * arr2[k][j]
print("\nMatrix Multiplication (A x B):")
for i in range(0, 3):
for j in range(0, 3):
print(arr3[i][j], end=" ")
print()
Output
Matrix A (3 x 3):
1 1 1
1 1 1
1 1 1
Matrix B (3 x 3):
2 2 2
2 2 2
2 2 2
Matrix Multiplication (A x B):
6 6 6
6 6 6
6 6 6
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.
We are working to cover every Single Concept in Python.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.