[Numpy-discussion] Matrix dot product over an axis(for a 3d array/list of matrices)

Charles R Harris charlesr.harris@gmail....
Thu Jul 15 11:58:54 CDT 2010


On Thu, Jul 15, 2010 at 10:38 AM, Emmanuel Bengio <bengioe@gmail.com> wrote:

> Hello,
>
> 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))
>
> Is there a way to do this in one instruction?
> Or is there a way to do this all using weave.inline?
>
>
Yes, there is a trick for this using a multiply with properly placed newaxis
followed by a sum. It uses more memory but for stacks of small arrays that
shouldn't matter. See the post
here<http://thread.gmane.org/gmane.comp.python.numeric.general/20360/focus=21033>.


Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100715/826be9f0/attachment.html 


More information about the NumPy-Discussion mailing list