[Numpy-discussion] help using np.einsum for stacked matrix multiplication
Sebastian Berg
sebastian at sipsolutions.net
Wed Oct 29 08:09:38 EDT 2014
On Mi, 2014-10-29 at 13:05 +0100, Sebastian Berg wrote:
> On Mi, 2014-10-29 at 20:39 +1100, Andrew Nelson wrote:
> > Dear list,
> > I have a 4D array, A, that has the shape (NX, NY, 2, 2). I wish to
> > perform matrix multiplication of the 'NY' 2x2 matrices, resulting in
> > the matrix B. B would have shape (NX, 2, 2). I believe that
> > np.einsum would be up to the task, but I'm not quite sure of the
> > subscripts I would need to achieve this.
> >
>
> Just remember that you sum over the columns of the first matrix and the
> rows of the second so those share the index:
>
> np.einsum('...ix, ...xj->...', a, b)
>
Nevermind, didn't read carefully. This is not possible since the
reduction operation is a sum, you will have to do at least two
operations.
> in the future, the np.dot predecessor (whatever it is) or the @ operator
> should be better at it though.
>
> - Sebastian
>
> > Can anyone help, please?
> >
> >
> > cheers,
> > Andrew.
> >
> >
> > --
> > _____________________________________
> > Dr. Andrew Nelson
> >
> >
> > _____________________________________
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141029/fa43e5dd/attachment.sig>
More information about the NumPy-Discussion
mailing list