-1

there can be better ways to get product but what is wrong in result

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]

1 Answers1

0

You can use numpy for this

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 is definalty faster than iteration

you can check this post Speed comparison. numpy vs python standard

Shabari nath k
  • 920
  • 1
  • 10
  • 23