这个问题对我来说有点棘手。输入是一个列表,如:
matmult([[1,2],[3,4]],[[1,0],[0,1]])
输出:
matmult([[1,2],[3,4]],[[1,0],[0,1]])
[[1,2],[3,4]]
matmult([[1,2,3],[4,5,6]],[[1,4],[2,5],[3,6]])
[[14, 32], [32, 77]]
这是我破旧的代码:
def matmult(m1,m2):
x=0
y=0
a=0
for value in range(0,len(m1)):
for other in range(0,len(m2)):
a=m1[value]*other[value]+other[value]*m2[value]
return(a)
其中matmult
是我的函数的名称。
帮助我。