[python] 矩陣向量相乘

  • 0
Vector Matrix multiplication in python 裡的 最佳解答 matrix-times-vector multiplication 很猛!




import operator
 import itertools

 def dot(x, y):
     assert len(x) == len(y)
     return sum(itertools.starmap(operator.mul, itertools.izip(x, y)))

 def matmult(m, v):
     return [dot(row, v) for row in m]



沒有留言 :

張貼留言