Python 3.x python3+;中矩阵的乘法;。我使用的是一行以下的代码,但得到的错误是TypeError:';int';对象不可调用

Python 3.x python3+;中矩阵的乘法;。我使用的是一行以下的代码,但得到的错误是TypeError:';int';对象不可调用,python-3.x,Python 3.x,可以有更好的方法获得产品,但结果有什么问题 from functools import reduce import operator def prod(iterable): return reduce(operator.mul,iterable,1) X = [[1,7,3], [3,5,8], [6,8,9]] Y = [[1,1,1,2], [6,7,3,0], [4,5,9,1]] resultTranspose=[list(i) for i in

可以有更好的方法获得产品,但结果有什么问题

from functools import reduce
import operator
def prod(iterable):
    return reduce(operator.mul,iterable,1)
X = [[1,7,3],
    [3,5,8],
    [6,8,9]]
Y = [[1,1,1,2],
    [6,7,3,0],
    [4,5,9,1]]
resultTranspose=[list(i) for i in zip(*Y)]

result=[[list(map(sum,list(map(prod,zip(i,j))))) for j in resultTranspose]
for i in X]

您可以为此使用
numpy

import numpy as np 

X = ([1,7,3],[3,5,8],[6,8,9])
Y = ([1,1,1,2],[6,7,3,0],[4,5,9,1])

result_mat = np.dot(X,Y) 
print(result_mat)    
Numpy肯定比迭代快

你可以查看这篇文章