【问题标题】:ValueError: matrices are not aligned, with correct shape of matricesValueError:矩阵未对齐,矩阵形状正确
【发布时间】:2017-11-19 17:19:58
【问题描述】:

我正在尝试使用 numpy 进行简单的点积运算。我知道尺寸应该对齐,就我而言,它们似乎与我对齐。我不知道这里有什么问题:

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

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

你能和我分享你的意见吗?

【问题讨论】:

  • 两个转置的点积对我有用
  • x = np.empty((784,1)); y = np.empty((10, 784)); np.dot(x.T, y.T)

标签: python numpy dot-product


【解决方案1】:

dot 将问题维度显示为错误的一部分。它们是什么?

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.]])

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 2012-11-01
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    相关资源
    最近更新 更多