Matrix Multiplication without using any built-in functions
rows=2
cols=3
M1=[[1,2,3],
[4,5,6]]
M2=[[7,8],
[9,10],
[11,12]]
my_list=[]
for l_row in range(0,rows):
temp_list=[]
for k in range(0,rows):
sum1=0
for l_col in range(0,cols):
sum1=sum1+(M1[l_row][l_col]*M2[l_col][k])
temp_list.append(sum1)
my_list.append(temp_list)
for row in my_list:
print(row)
from random import randrange
rows=4
cols=4
M1=[]
M2=[]
for j in range(0,rows):
temp1=[]
for k in range(0,cols):
x=randrange(10)
temp1.append(x)
#print(x)
M1.append(temp1)
print(M1)
print("M1 shown above ")
for j in range(0,cols):
temp1=[]
for k in range(0,rows):
x=randrange(10)
temp1.append(x)
M2.append(temp1)
print(M2)
print('M2 is shown above ')
my_list=[]
for l_row in range(0,rows):
temp_list=[]
sum1=0
for k in range(0,rows):
sum1=0
for l_col in range(0,cols):
sum1=sum1+(M1[l_row][l_col]*M2[l_col][k])
temp_list.append(sum1)
my_list.append(temp_list)
for row in my_list:
print(row)