Skip to content

Commit 27c282a

Browse files
authored
Create Python code to multiply two matrices
1 parent 9bccf15 commit 27c282a

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#https://www.facebook.com/permalink.php?story_fbid=2376635879298242&id=100008555587566
2+
#Subscribed and liked ny Aryan Kumar
3+
4+
# Program to multiply two matrices
5+
A=[]
6+
n=int(input("Enter N for N x N matrix: "))
7+
print("Enter the element ::>")
8+
for i in range(n):
9+
row=[]
10+
for j in range(n):
11+
row.append(int(input()))
12+
A.append(row)
13+
print(A)
14+
print("Display Array In Matrix Form")
15+
for i in range(n):
16+
for j in range(n):
17+
print(A[i][j], end=" ")
18+
print()
19+
B=[]
20+
n=int(input("Enter N for N x N matrix : "))
21+
#use list for storing 2D array
22+
#get the user input and store it in list (here IN : 1 to 9)
23+
print("Enter the element ::>")
24+
for i in range (n):
25+
row=[]
26+
for j in range(n):
27+
row.append(int(input()))
28+
B.append(row)
29+
print(B)
30+
#Display the 2D array
31+
print("Display Array In Matrix Form")
32+
for i in range(n):
33+
for j in range(n):
34+
print(B[i][j], end=" ")
35+
print()
36+
result = [[0,0,0], [0,0,0], [0,0,0]]
37+
for i in range(len(A)):
38+
for j in range(len(B[0])):
39+
for k in range(len(B)):
40+
result[i][j] += A[i][k] * B[k][j]
41+
print("The Resultant Matrix Is ::>")
42+
for r in result:
43+
print(r)

0 commit comments

Comments
 (0)