-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmat_multi_func.py
More file actions
31 lines (31 loc) · 1.11 KB
/
Copy pathmat_multi_func.py
File metadata and controls
31 lines (31 loc) · 1.11 KB
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
#Write a python program to do multiplication of matrix
def formatMatrix(rows=int(),col=int()):
l=[]
for i in range(rows):
l_1=[]
for j in range(col):
a=int(input(f"Enter element[{i}][{j}]:"))
l_1.append(a)
l.append(l_1)
return l
def multiplyMatrix(mat1=list(),mat2=list()):
result=[]
#To check matrix multiplicity
if len(mat1[0])!=len(mat2):
raise Exception("The given matrix can't be multiplied")
quit()
#To print result block
for i in range(len(mat1)):
res_row=[]
for j in range(len(mat2[0])):
res_row.append(0)
result.append(res_row)
#To append matrix using main logic
for i in range(len(mat1)): #interates the no of times as rows in mat1
for j in range(len(mat2[0])): #interates the no of times as columns in mat2
for k in range(len(result)): #Interrates the number of times the rows in result
result[i][j]+=mat1[i][k]*mat2[k][j]
return result
m=formatMatrix(2,3)
n=formatMatrix(3,7)
print(multiplyMatrix(m,n))