题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
matrix_1_n = int(input()) matrix_m = int(input()) matrix_2_k = int(input()) matrix_1 = [] for _ in range(matrix_1_n): # 行 matrix_1.append(list(map(lambda x: int(x), input().split()))) matrix_2 = [] for _ in range(matrix_m): matrix_2.append(list(map(lambda x: int(x), input().split()))) matrix_0 = [0 for _ in range(matrix_2_k)] matrix = [matrix_0.copy() for _ in range(matrix_1_n)] for i in range(matrix_1_n): for j in range(matrix_2_k): for k in range(matrix_m): matrix[i][j] += matrix_1[i][k] * matrix_2[k][j] for i in matrix: for j in i: print(j, end=' ') print()
直接套用公式来编码