Theano 中的元素智能矩阵乘法
Element wise matrix multiplication in Theano
我可以看到使用 numpy 的逐元素矩阵乘法可以通过 * 运算符完成。
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))))
如果我尝试以下操作(基本上就是您的代码):
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.]]
所以,它适合我。
我可以看到使用 numpy 的逐元素矩阵乘法可以通过 * 运算符完成。
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))))
如果我尝试以下操作(基本上就是您的代码):
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.]]
所以,它适合我。