Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def transpose(Mat) :
- T_mat = []
- for i in range(len(Mat[0])) :
- temp = []
- for j in range(len(Mat)) :
- temp.append(Mat[j][i])
- T_mat.append(temp)
- return T_mat
- def main() :
- row_1 = int(input("Enter the number of rows in the First Matrix : "))
- col_1 = int(input("Enter the number of columns in the First Matrix : "))
- row_2 = col_1
- col_2 = int(input("\nEnter the number of columns in the Second Matrix : "))
- M1 , M2 , mul_mat = [],[],[]
- for i in range(row_1) :
- temp = []
- for j in range(col_1) :
- elem = eval(input("Enter the Element of the First Matrix at the Position ; Row : {} , Column : {} =====> ".format(i+1,j+1)))
- temp.append(elem)
- M1.append(temp)
- print()
- for i in range(row_2) :
- temp = []
- for j in range(col_2) :
- elem = eval(input("Enter the Element of the Second Matrix at the Position ; Row : {} , Column : {} =====> ".format(i+1,j+1)))
- temp.append(elem)
- M2.append(temp)
- print("\nMatrix A : ")
- for i in M1 :
- for j in i :
- print(j , end = " ")
- print()
- print("\nMatrix B : ")
- for i in M2 :
- for j in i :
- print(j , end = ' ')
- print()
- M2 = transpose(M2)
- for i in range(len(M1)) :
- temp = []
- for j in range(len(M2)) :
- sum_val = 0
- for k in range(len(M2[0])) :
- sum_val += (M1[i][k] * M2[j][k])
- temp.append(sum_val)
- mul_mat.append(temp)
- print("\nMultiplication of A over B (A X B) : ")
- for i in mul_mat :
- for j in i :
- print(j , end = ' ')
- print()
- main()
Add Comment
Please, Sign In to add comment