9
考虑numpy的广播的以下示例:Theano广播不同到numpy的的
import numpy as np
import theano
from theano import tensor as T
xval = np.array([[1, 2, 3], [4, 5, 6]])
bval = np.array([[10, 20, 30]])
print xval + bval
如所预期的,所述载体bval
被添加到基质xval
的各行并且输出是:
[[11 22 33]
[14 25 36]]
试图在gano版本的theano中复制相同的行为:
x = T.dmatrix('x')
b = theano.shared(bval)
z = x + b
f = theano.function([x], z)
print f(xval)
我得到以下错误:
ValueError: Input dimension mis-match. (input[0].shape[0] = 2, input[1].shape[0] = 1)
Apply node that caused the error: Elemwise{add,no_inplace}(x, <TensorType(int64, matrix)>)
Inputs types: [TensorType(float64, matrix), TensorType(int64, matrix)]
Inputs shapes: [(2, 3), (1, 3)]
Inputs strides: [(24, 8), (24, 8)]
Inputs scalar values: ['not scalar', 'not scalar']
我明白Tensor
对象,如x
有broadcastable
属性,但我不能找到一种方法来1)正确设置此为shared
对象或2)正确地拥有它推断。如何在theano中重新实现numpy的行为?
只是提醒:不在文档中:) – 2015-01-14 19:23:41
它在那里:http://deeplearning.net/software/theano/library/compile/shared.html#theano.compile.sharedvalue.shared您在哪里寻找它?也许我们需要在另一个地方添加它。 – nouiz 2015-01-18 16:05:23
啊对不起,它在克瓦格斯那里......没有看到它。无论如何,我认为这是一个重要的功能,可能会保证更多的可见性? – 2015-01-18 16:58:27