Skip to content

Commit beef621

Browse files
add MatrixMultiplication.py
1 parent 7875a63 commit beef621

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

MatrixMultiplication.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Program to multiply two matrices using nested loops
2+
3+
# take a 3 by 3 matrix
4+
A = [[1, 2, 3],
5+
[4, 5, 6],
6+
[7, 8, 9]]
7+
8+
# take a 3 by 4 matrix
9+
B = [[100, 200, 300, 400],
10+
[500, 600, 700, 800],
11+
[900, 1000, 1100, 1200]]
12+
13+
result = [[0, 0, 0, 0],
14+
[0, 0, 0, 0],
15+
[0, 0, 0, 0]]
16+
17+
# iterating by row of A
18+
for i in range(len(A)):
19+
20+
# iterating by coloum by B
21+
for j in range(len(B[0])):
22+
23+
# iterating by rows of B
24+
for k in range(len(B)):
25+
result[i][j] += A[i][k] * B[k][j]
26+
27+
for r in result:
28+
print(r)

0 commit comments

Comments
 (0)