[Numpy-discussion] help using np.einsum for stacked matrix multiplication
sebastian at sipsolutions.net
Wed Oct 29 08:05:52 EDT 2014
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)
in the future, the np.dot predecessor (whatever it is) or the @ operator
should be better at it though.
> Can anyone help, please?
> Dr. Andrew Nelson
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion