Why can't a 3, 2 matrix be multiplied by a 2, 2 matrix with NumPy? -


using numpy , attempting multiply matrices doesn't work. example

import numpy np  x = np.matrix('1, 2; 3, 8; 2, 9') y = np.matrix('5, 4; 8, 2')  print(np.multiply(x, y)) 

can return

traceback (most recent call last):   file "vector-practice.py", line 6, in <module>     print(np.multiply(x, y)) valueerror: operands not broadcast shapes (3,2) (2,2) 

i understand can't multiply these shapes, why not? can multiply these 2 matrices on paper, why not in numpy? missing obvious here?

np.multiply multiply arguments element-wise., it's not matrix multiplication. when have matrices, need use * or np.dot matrix multiplication.

x * y #matrix([[21,  8], #        [79, 28], #        [82, 26]])  np.dot(x, y) #matrix([[21,  8], #        [79, 28], #        [82, 26]]) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -