-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix multipliation.py
More file actions
44 lines (33 loc) · 936 Bytes
/
Copy pathmatrix multipliation.py
File metadata and controls
44 lines (33 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#matrix multiplication
def matro(x,y):
gg=[]
print("enter the matrix elements")
for i in range(x):
tempo=[]
for j in range(y):
a=int(input())
tempo.append(a)
gg.append(tempo)
return gg
r1=int(input("enter the number of rows of the matrices"))
c1=int(input("enter the number of columns of the matrix"))
mat1=matro(r1,c1)
r2=int(input("enter the number of rows of the matrices"))
c2=int(input("enter the number of columns of the matrix"))
mat2=matro(r2,c2)
print(mat1)
print(mat2)
if(c1!=r2):
print("matrix multiplication not possible")
else:
mult=[]
for i in range(r1):
tempo=[]
for j in range(c2):
su=0
for k in range(c1):
pro=mat1[i][k]*mat2[k][j]
su+=pro
tempo.append(su)
mult.append(tempo)
print(mult)