2016-06-15 21 views
1

我需要創建一個固定的長度(長度等於一些其他張量矢量的大小通過)零矢量theano。創建一個零矢量,並修改它在theano

def some_fun(self, y) 
    x_h = T.fvector('x_h') 
    ret = T.alloc(0, x_h) 
    vec_h = theano.function(inputs=[x_h], outputs=ret) 
    vec=vec_h(y.shape[0]) 
    vec[T.arange(y.shape[0]),y]=1 

當我運行此我得到錯誤「形狀參數的Alloc必須是整數,但參數0是不適用的節點:x_h」

可能很大的錯誤,因爲我是新到theano。

感謝

回答

1

你試過theano.tensor.zeros_like?看起來這應該是你嘗試去做的捷徑。

然後,當你得到

"TypeError: 'TensorVariable' object does not support item assignment"

您可以通過使用theano.tensor.set_subtensor,而不是更換線vec[T.arange(y.shape[0]),y]=1

+0

是的,這將工作,但任務vec [T.arange(y.shape [0]),y] = 1顯示錯誤。 – hunch

+0

什麼是錯誤? – harshil

+0

對不起,我應該在前面提到,「TypeError:'TensorVariable'對象不支持項目分配」 – hunch