简体   繁体   中英

ValueError: matrices are not aligned, with correct shape of matrices

I'm trying to make a simple dot product operation with numpy. I am aware of the fact that dimensions should be aligned, and in my case, they seem aligned to me. I can't what is the problem here:

x.shape: (784, 1) y.shape: (10, 784)

z = np.dot(x.T,y.T)

Could you please share your opinions with me?

dot shows the problem dimensions as part of the error. What are they?

In [556]: np.dot(np.ones((784,1)),np.ones((10,784)))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-556-616373e8d85c> in <module>()
----> 1 np.dot(np.ones((784,1)),np.ones((10,784)))

ValueError: shapes (784,1) and (10,784) not aligned: 1 (dim 1) != 10 (dim 0)

In [557]: np.dot(np.ones((784,1)).T,np.ones((10,784)))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-557-bc2abea61020> in <module>()
----> 1 np.dot(np.ones((784,1)).T,np.ones((10,784)))

ValueError: shapes (1,784) and (10,784) not aligned: 784 (dim 1) != 10 (dim 0)

In [558]: np.dot(np.ones((784,1)).T,np.ones((10,784)).T)
Out[558]: 
array([[ 784.,  784.,  784.,  784.,  784.,  784.,  784.,  784.,  784.,
         784.]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM