(TypeError) numpy 和 theano 中的点操作

(TypeError) dot operation in numpy and theano

我写了如下代码:

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)returnsarray([ 9, 12, 15])。我认为 f(a,b) returns 同样的事情,但它失败了(TypeError)。错误消息显示

Wrong number of dimensions: expected 2, got 1 with shape (2,).

发生什么事了?

将第 4 行更改为 p=theano.tensor.dvector('p')。 Theano 在输入方面比 numpy 更严格。