[Numpy-discussion] Matrix dot product over an axis(for a 3d array/list of matrices)
Thu Jul 15 15:31:14 CDT 2010
On 2010-07-15, at 12:38 PM, Emmanuel Bengio <firstname.lastname@example.org> wrote:
> I have a list of 4x4 transformation matrices, that I want to "dot with" another list of the same size (elementwise).
> Making a for loop that calculates the dot product of each is extremely slow,
> I thought that maybe it's due to the fact that I have thousands of matrices and it's a python for loop and there's a high Python overhead.
> I do something like this:
> >> for a,b in izip(Rot,Trans):
> >> c.append(numpy.dot(a,b))
If you need/want more speed than the solution Chuck proposed, you should check out Cython and Tokyo. Cython lets you write loops that execute at C speed, whereas Tokyo provides a Cython level wrapper for BLAS (no need to go through Python code to call NumPy). Tokyo was designed for exactly your use case: lots of matrix multiplies with relatively small matrices, where you start noticing the Python overhead.
More information about the NumPy-Discussion