【问题标题】:Element wise matrix multiplication in TheanoTheano中的元素矩阵乘法
【发布时间】:2016-04-23 17:45:20
【问题描述】:

我可以看到使用 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))))

【问题讨论】:

  • 如果你只想要元素乘法,把z = x + y改成z = x * y
  • @ajcr 这是*。 + 是错误的。已更正
  • 该代码对我有用(产生一个 10 x 10 的 1 数组),你看到了什么结果?

标签: python numpy theano theano-cuda


【解决方案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.]]

所以,它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 2013-12-27
    • 2015-01-08
    相关资源
    最近更新 更多