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]
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))
Comments
Leave a comment