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