Python 2.7 矩阵与三维张量之间的无点积

Python 2.7 矩阵与三维张量之间的无点积,python-2.7,theano,theano.scan,Python 2.7,Theano,Theano.scan,我有一个矩阵和三维张量,定义如下: import numpy as np import theano import theano.tensor as T a = T.matrix('a', dtype='float32') c = T.tensor3('c',dtype='float32') d = T.batched_dot(c, a) g = theano.function([a,c],d) Y = [[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],

我有一个矩阵和三维张量,定义如下:

import numpy as np
import theano
import theano.tensor as T

a = T.matrix('a', dtype='float32')
c = T.tensor3('c',dtype='float32')
d = T.batched_dot(c, a)
g = theano.function([a,c],d)
Y = [[[1, 0, 0, 0],  [0, 1, 0, 0],  [0, 0, 1, 0], [0, 0, 0, 0]], [[0, 0 ,0, 0], [0, 1, 0, 0],[0, 0, 1, 0],[0, 0, 0, 1]]]
X = [[ 0.5052417 ,  0.22012063,  0.21787818,  0.41821062, 1, 1, 1, 0], [ 0.48668074,  0.26137591,  0.240702  ,  0.41308364, 0, 1, 1, 1]]
x = np.array(X, dtype='float32')
y = np.array(Y, dtype='float32')
print g(x[:,0:4], y)
虽然最后给出了正确的答案,但在中间却显示出许多错误,如

ValueError: get_scalar_constant_value detected deterministic IndexError: x.shape[2] when x.ndim=2. x=Subtensor{int64}.0
ERROR (theano.gof.opt): Optimization failure due to: local_gpua_gemmbatch
ERROR (theano.gof.opt): node: BatchedDot(c, a)
ERROR (theano.gof.opt): TRACEBACK:
ValueError: get_scalar_constant_value detected deterministic IndexError: x.shape[2] when x.ndim=2. x=Subtensor{int64}.0
我的预期产出是

[[ 0.50524169  0.22012062  0.21787818  0.        ]
[ 0.          0.2613759   0.240702    0.41308364]]

我怎样才能正确地将这两者相乘?

您解决了这个问题吗?我有完全相同的问题…嗨@MohamadGhafourian,我改变了Y的结构。我把它改成了一个简单的矩阵,并执行了元素矩阵乘法。以前的
Y
是对角矩阵的矩阵。现在它是简单的矩阵。新的
Y
是[[1,1,1,1,1,1,1,0],[1,1,1,1,0,1,1,1]]。