[SciPy-User] Dot product of two arrays of vectors
Alexander Kalinin
alec.kalinin@gmail....
Thu Oct 4 06:25:58 CDT 2012
Hello, SciPy,
Could you, please, explain me, what is the most standard way in NumPy to
calculate a dot product of two arrays of vectors, like in MatLab? For
example, consider two numpy arrays of vectors:
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([[3, 2, 1], [6, 5, 4]])
For the cross product we have convenient function numpy.cross:
>>> np.cross(a, b)
array([[ -4, 8, -4],
[-10, 20, -10]])
But the numpy.dot product for the arrays of vectors do the matrix
multiplication:
>>> np.dot(a, b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: objects are not aligned
Yes, I can emulate the dot product code like:
np.sum(a * b, axis = 1).reshape(-1, 1)
but may be there is exist more standard way to do the dot product?
Sincerely,
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121004/723b87c7/attachment.html
More information about the SciPy-User
mailing list