题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
import sys x, y, z = int(input().strip()), int(input().strip()), int(input().strip()) ma = [list(map(int, input().strip().split())) for i in range(x)] mb = [list(map(int, input().strip().split())) for i in range(y)] def matrix_multiply(la, lb): res = 0 for i in range(len(la)): res += la[i] * lb[i] return res def col_list(matrix, col): res = [] for i in matrix: res.append(i[col]) return res mbc = [col_list(mb, i) for i in range(z)] res = [[0 for j in range(z)] for i in range(x)] for i in range(x): for j in range(z): res[i][j] = matrix_multiply(ma[i], mbc[j]) for i in range(len(res)): print(*res[i], sep=' ')