题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
import sys inp = sys.stdin.readlines() x = int(inp[0].strip()) y = int(inp[1].strip()) z = int(inp[2].strip()) arr1=[] arr2=[] for i in range(3, len(inp)): if i<x+3: line = inp[i].strip().split() arr1.append(list(map(int, line))) else: line = inp[i].strip().split() arr2.append(list(map(int, line))) arr3=[[0]*z for _ in range(x)] for i in range(x): for j in range(z): v = sum([arr1[i][t] * arr2[t][j] for t in range(y)]) arr3[i][j] = v for i in range(x): print(' '.join(map(str, arr3[i])))