Answer to Question #316630 in Python for babu

Question #316630

qusetion: Multiplication of matrix ??


input:

3 3

1 2 3

4 5 6

7 8 9


10 11 12

13 14 15

16 17 18


output:-

[84 90 96]

[201 216 231]

[318 342 366]





1
Expert's answer
2022-03-23T13:44:43-0400
def multiplication(matrix1, matrix2):
    result_matrix = []
    for i in range(len(matrix1)):
        ix = []
        for j in range(len(matrix2[0])):
            x = 0
            for k in range(len(matrix1[0])):
                x += matrix1[i][k] * matrix2[k][j]
            ix.append(x)
        result_matrix.append(ix)
    return result_matrix;


def input_matrix(R, C):
    matrix = []
    for i in range(R):
        a =[]
        inp = input().split()
        for j in range(C):
             a.append(int(inp[j]))
        matrix.append(a)
    return matrix


def print_matrix(matrix):
    for i in range(len(matrix)):
        for j in range(len(matrix[0])):
            print(matrix[i][j], end = "\t")
        print()
    
info = input()
info_arr = info.split()


matrix1 = input_matrix(int(info_arr[0]), int(info_arr[1]))
print()
matrix2 = input_matrix(int(info_arr[1]), int(info_arr[0]))
print()
    
print_matrix(multiplication(matrix1, matrix2))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS