Vectorized way of calculating row-wise dot product two matrices with Scipy
I want to calculate the row-wise dot product of two matrices of the same dimension as fast as possible. This is the way I am doing it: import numpy as np a = np.array([[1,2,3], [3,4,5]]) b = np.array([[1,2,3], [1,2,3]]) result = np.array([]) for row1, row2 in a, b: result = np.append(result, np.dot(row1, row2)) print result and of course the output is: [ 26. 14.] Check out numpy.einsum for another method: In [52]: a Out[52]: array([[1, 2, 3], [3, 4, 5]]) In [53]: b Out[53]: array([[1, 2, 3], [1, 2, 3]]) In [54]: einsum('ij,ij->i', a, b) Out[54]: array([14, 26]) Looks like einsum is a bit