Blogger Tips and TricksLatest Tips And TricksBlogger Tricks

Program to Perform Matrix Multiplication in python


import numpy as np
array = list()
array2 = list()
result= list()
print ("Enter details for Matrix A")
i = int(input("How many row: "))
j = int(input("How many column: "))
s=(i,j)
result=np.zeros(s, dtype=np.int)
for x in range(i):
    if i <= 0 or i>20:
         print("Failure!")
         break
    elif j <= 0 or j>20:
         print("Failure!")
         break
    else:
        for y in range(j):
             num = int(input("Value: "))
             array.append(int(num))
a = np.reshape(array,(i,j))
print ("The A matrix is ")
print (a)

print ("Enter details for Matrix B")
i1 = int(input("How many row: "))
j1= int(input("How many column: "))
 
for x1 in range(i1):
    if i1 <= 0 or i1 > 20:
         print("Failure!")
         break
    elif j1 <= 0 or j1>20:
         print("Failure!")
         break
    else:
        for y1 in range(j1):
             num1 = int(input("Value: "))
             array2.append(int(num1))
b = np.reshape(array2,(i1,j1))

print ("The B Matrix is :")
print (b)
 
for i2 in range(len(a)):
 
   for j2 in range(len(b[0])):
 
       for k2 in range(len(b)):
           result[i2][j2] += a[i2][k2] * b[k2][j2]

for r in result:
   print(r)

1 comment:

  1. Tuscany - Tuscany - Titanium Pan Chips
    Tuscany. titanium trimmer Tuscany is a fusion fusion of fine granules with pure titanium earrings fine spices that offers a unique mens titanium wedding rings texture, titanium bmx frame rich flavour and character. Tuscany is titanium sponge made $6.95 · ‎In stock

    ReplyDelete

Flag Counter