Skip to content

Commit a8d22b8

Browse files
authored
added new python
1 parent 99cf7d7 commit a8d22b8

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

bests.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Program to multiply two matrices using nested loops
2+
3+
# subcri
4+
5+
# 3x3 matrix
6+
7+
X = [[12,7,3],
8+
9+
[4 ,5,6],
10+
11+
[7 ,8,9]]
12+
13+
# 3x4 matrix
14+
15+
Y = [[5,8,1,2],
16+
17+
[6,7,3,0],
18+
19+
[4,5,9,1]]
20+
21+
# result is 3x4
22+
23+
result = [[0,0,0,0],
24+
25+
[0,0,0,0],
26+
27+
[0,0,0,0]]
28+
29+
# iterate through rows of X
30+
31+
for i in range(len(X)):
32+
33+
# iterate through columns of Y
34+
35+
for j in range(len(Y[0])):
36+
37+
# iterate through rows of Y
38+
39+
for k in range(len(Y)):
40+
41+
result[i][j] += X[i][k] * Y[k][j]
42+
43+
for r in result:
44+
45+
print(r)

0 commit comments

Comments
 (0)