[Numpy-discussion] For broadcasting, can m by n by k matrix be multiplied with n by k matrix?

C W tmrsg11 at gmail.com
Fri Apr 19 18:23:40 EDT 2019


Hello all,

Can an m x n x k matrix be multiplied with n x k matrix? Looking at the
Numpy doc page 46 (
https://docs.scipy.org/doc/numpy-1.11.0/numpy-user-1.11.0.pdf), it should
work.

It says the following:
A (3d array): 15 x 3 x 5
B (2d array):         3 x 5
Result (3d array): 15 x 3 x 5

But, the rule did not work for me. Here's my toy example:
>>> a = np.arange(3*4*5).reshape(3,4,5)
>>> b = np.arange(4*5).reshape(4,5)
>>> np.dot(a, b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: shapes (3,4,5) and (3,5) not aligned: 5 (dim 2) != 3 (dim 0)

Am I miss reading something? Thank you in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190419/4320a7f6/attachment.html>


More information about the NumPy-Discussion mailing list