题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
根据输入得到A,B两个矩阵,然后直接根据题目中的公式求输出矩阵。
import sys x, y, z = int(input()), int(input()), int(input()) A = [[0] * y for _ in range(x)] B = [[0] * z for _ in range(y)] ans = [[0] * z for _ in range(x)] for i in range(x): A[i] =[int(m) for m in input().split(' ')] for i in range(y): B[i] = [int(m) for m in input().split(' ')] for i in range(x): for j in range(z): cal = 0 for k in range(y): cal += A[i][k] * B[k][j] ans[i][j] = cal for i in range(x): out = [str(m) for m in ans[i]] print(' '.join(out))