[Numpy-discussion] Matrix dot product over an axis(for a 3d array/list of matrices)
Charles R Harris
charlesr.harris@gmail....
Thu Jul 15 13:09:57 CDT 2010
On Thu, Jul 15, 2010 at 12:00 PM, Emmanuel Bengio <bengioe@gmail.com> wrote:
> Ok I get it. Thanks!
>
> Numpy syntax that works for me:
> numpy.sum(a[:,:,:,numpy.newaxis]*b[:,numpy.newaxis,:,:],axis=-2)
>
>
The leading "..." gives the same thing, but iterates over all the leading
indicies in case you want multidimensional arrays of matrices ;) You can
also use the sum method which might be a bit more economical:
(a[:,:,:,numpy.newaxis]*b[:,numpy.newaxis,:,:]).sum(axis=-2)
How do the execution times compare?
<snip>
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100715/dbca2328/attachment.html
More information about the NumPy-Discussion
mailing list