我写了以下代码:
import theano
import numpy
p=theano.tensor.dmatrix('p')
q=theano.tensor.dmatrix('q')
r=theano.tensor.dot(p,q)
f=theano.function([p,q], r)
a=numpy.array([1,2])
b=numpy.array([[1,2,3],[4,5,6]])
然后numpy.dot(a,b)
返回array([ 9, 12, 15])
.我认为f(a,b)
返回相同的东西,但它失败了(类型错误(。错误消息显示
错误的维数:预期为 2,形状为 (2,( 为 1。
发生了什么事情?
将第
4 行更改为 p=theano.tensor.dvector('p')
。Theano对打字比numpy更严格。