Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Theano中的元素矩阵乘法_Python_Numpy_Theano_Theano Cuda - Fatal编程技术网

Python Theano中的元素矩阵乘法

Python Theano中的元素矩阵乘法,python,numpy,theano,theano-cuda,Python,Numpy,Theano,Theano Cuda,我可以看到使用numpy的元素矩阵乘法可以用*运算符完成 print np.mat(np.ones((10,10)))*np.mat(np.ones((10,10))) 但不能让它在没有的情况下工作。我试过的代码是 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))))

我可以看到使用numpy的元素矩阵乘法可以用*运算符完成

print np.mat(np.ones((10,10)))*np.mat(np.ones((10,10)))
但不能让它在没有的情况下工作。我试过的代码是

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.]]

所以,它对我很有用。

如果你只想进行元素乘法,请将
z=x+y
更改为
z=x*y
@ajcr it s*我错在那里了。修正了我的代码(生成一个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.  1.]]