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

Emmanuel Bengio bengioe@gmail....
Thu Jul 15 12:32:50 CDT 2010

```>Could you place all Rot's into the same array and all the Trans's into the
same array?
Well I guess since they're all the same size. I would just have to do
array(a). But the result of the dot product of two 3d arrays is most
unexpected:
>>> a = numpy.ones((4,5,6))
>>> a = numpy.ones((10,4,4))
>>> b = numpy.ones((10,4,4))
>>> c = numpy.dot(a,b)
>>> c.shape
(10, 4, 10, 4) #Hmm, not what a newbie expects D:

>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

Hmm, I'm not sure I understand what is being done there.

On 15 July 2010 12:45, John Salvatier <jsalvati@u.washington.edu> wrote:

> Could you place all Rot's into the same array and all the Trans's into the
> same array? If you have the first index of each array refer to which array
> it is numpy.dot should work fine, since numpy.dot just does the dot product
> over the second to last and last indexes.
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html
>
> John
>
> On Thu, Jul 15, 2010 at 9: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?
>>
>> --
>>
>>
>>          Emmanuel
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>

--

Emmanuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100715/6a184350/attachment.html
```