We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 70f441b + ed64a78 commit 4c81300Copy full SHA for 4c81300
Matrix Multiplication using Nested Loop.py
@@ -0,0 +1,25 @@
1
+# Program to multiply two matrices using nested loops
2
+
3
+# 3x3 matrix
4
+X = [[12,7,3],
5
+ [4 ,5,6],
6
+ [7 ,8,9]]
7
+# 3x4 matrix
8
+Y = [[5,8,1,2],
9
+ [6,7,3,0],
10
+ [4,5,9,1]]
11
+# result is 3x4
12
+result = [[0,0,0,0],
13
+ [0,0,0,0],
14
+ [0,0,0,0]]
15
16
+# iterate through rows of X
17
+for i in range(len(X)):
18
+ # iterate through columns of Y
19
+ for j in range(len(Y[0])):
20
+ # iterate through rows of Y
21
+ for k in range(len(Y)):
22
+ result[i][j] += X[i][k] * Y[k][j]
23
24
+for r in result:
25
+ print(r)
0 commit comments