[算法导论] 矩阵乘法
作者:互联网
import numpy as np
def matmul(a, b):
return np.matmul(a, b)
def manual_matmul(a, b):
C = []
for x in range(len(a)):
tp = []
for y in range(len(b[0])):
tp.append(sum(a[x][k]*b[k][y] for k in range(len(b))))
C.append(tp)
return np.array(C)
if __name__ == '__main__':
# A=[],B=[] 这是错的
A = []
B = []
na, ma = map(int, input().split())
# 按行存储就可以
for i in range(na):
tmp = []
tmp = list(map(int, input().split()))
A.append(tmp)
nb, mb = map(int, input().split())
for i in range(nb):
tmp = []
tmp = list(map(int, input().split()))
B.append(tmp)
print("熊熊")
print(A)
print(B)
#print(matmul(A, B))
print(manual_matmul(A, B))
标签:tmp,__,int,导论,矩阵,matmul,range,print,乘法 来源: https://blog.csdn.net/Trance95/article/details/120440651