2016-04-23 137 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.]] 

所以,它爲我工作。