在編譯theano
中的函數時,可以通過指定updates=[(X, new_value)]
來更新共享變量(比如X)。 現在我想更新共享變量的唯一子集:如何在Theano中分配/更新張量共享變量的子集?
from theano import tensor as T
from theano import function
import numpy
X = T.shared(numpy.array([0,1,2,3,4]))
Y = T.vector()
f = function([Y], updates=[(X[2:4], Y)] # error occur:
# 'update target must
# be a SharedVariable'
的代碼將引發一個錯誤「更新的目標必須是SharedVariable」,我想這意味着更新的目標不能是不共享變量。那麼有沒有什麼辦法可以編譯一個函數來僅僅使用共享變量的子集呢?
+1救了我的一天。謝謝! – displayname 2014-06-15 15:09:04
並更新非連續值:'X_update =(X,T.set_subtensor(X [[2,4]],Y))' – 2015-01-07 14:55:14
[Here](http://deeplearning.net/software/theano/tutorial/ faq_tutorial.html)它表示'inc_subtensor'優先於'set_subtensor' – Kirbies 2015-08-03 12:46:23