题解 | #矩阵乘法#
矩阵乘法
http://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b
思路清晰
# 两个列表相乘
def ls_x(a,b):
c=zip(a,b)
return sum([i*j for i,j in c])
# 第一个二维列表的行和列;第二个二维列表的行和列
row1,col1 = int(input()),int(input()) # 行、列
row2,col2= col1,int(input())
# 三个二维列表
arr1 = [list(map(int,input().split())) for i in range(row1)]
arr2 = [list(map(int,input().split())) for i in range(row2)]
arr3 = [[1 for i in range(col2)] for j in range(row1)]
# 循环,求解
for row in range(row1):
for col in range(col2):
arr3[row][col] = ls_x(arr1[row],[arr2[i][col] for i in range(row2)])
# 输出
for i in arr3:
for j in i:
print(j,end=' ')
print()