我正在尝试运行Theano文档中的逻辑回归示例。代码如下所示:
运行此代码时,我得到了以下错误
Traceback (most recent call last):
File "theano_log_reg.py", line 54, in <module>
pred, err = train(D[0], D[1])
File "D:\Programs\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\theano\compile\function_module.py", line 788, in __call__
allow_downcast=s.allow_downcast)
File "D:\Programs\WinPython-64bit-3.4.4.4Qt5\python-3.4.4.amd64\lib\site-packages\theano\tensor\type.py", line 178, in filter
data.shape)
TypeError: ('Bad input argument to theano function with name "theano_log_reg.py:49" at index 1 (0-based)', 'Wrong number of dimensions: expected 2, got 1 with shape (400,).')
我对Theano和numpy还不熟悉,无法解决这个错误。任何帮助都将不胜感激。我正在使用WinPython(Python 3.4)运行最新的Theano版本。
回答:
明白了,在我的情况下,输出变量y应该是一个浮点数向量T.dvector("y")
,但我却定义成了矩阵T.dmatrix("y")
。这就是为什么点积y * T.log(p_1)
没有发生的原因。