# 2 3 3 4 # 1 2 3 # 4 5 6 # 1 2 3 4 # 5 6 7 8 # 9 10 11 12 lst1, lst2 = [], [] n1,m1,n2,m2 = map(int,input().split()) for i in range(n1): nums = list(map(int,input().split())) #输入一行数据 lst1.append(nums) for i in range(n2): nums = list(map(int,input().split())) lst2.append(nums) res = [] for i in range(n1): res.append([]) for j in range(m2): lst4 = [] lst3 = lst1[i] for k in range(n2): lst4.append(lst2[k][j]) res_num = sum(map(lambda x,y:x*y,lst3,lst4)) res[i].append(res_num) print(res) import numpy as np print('numpy:',np.dot(lst1,lst2)) #使用numpy验证结果
2 3 3 4 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 10 11 12 [[38, 44, 50, 56], [83, 98, 113, 128]] numpy: [[ 38 44 50 56] [ 83 98 113 128]]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)