2016-04-23 141 views
0

我可以看到使用numpy元素明智的矩阵乘法可以用*操作符完成。Theano元素明智的矩阵乘法

print np.mat(np.ones((10,10)))*np.mat(np.ones((10,10))) 

但无法让它在theano下工作。我试过的代码是

x = T.dmatrix('x') 
y = T.dmatrix('y') 
z = x * y 
f1 = theano.function([x, y], z) 

print f1(np.mat(np.ones((10,10))),np.mat(np.ones((10,10)))) 
+0

如果您只是想要元素乘法,请将'z = x + y'更改为'z = x * y'。 –

+0

@ajcr它是*。 +在那里是错误的。已更正 – user567879

+0

该代码适用于我(生成10乘10的数组),您看到了什么结果? –

回答

1

如果我尝试以下方法(这基本上是你的代码):

import theano 
import theano.tensor as T 

import numpy as np 

x = T.dmatrix('x') 
y = T.dmatrix('y') 
z = x * y 
f1 = theano.function([x, y], z) 

print f1(np.mat(np.ones((10,10))),np.mat(np.ones((10,10)))) 

我得到如下:

[[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] 
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]] 

所以,它为我工作。