Reputation: 719
I'm trying to select multiple elements from a matrix using a changing vector, which is sent to my Theano function at each iteration. But when I try running the code I get the following error for the last line (selecting from W)
ValueError: setting an array element with a sequence.
The declaration is:
x = T.vector('x', dtype='int32')
y = T.vector('y', dtype='int32')
net = net(rng=rng, x=x, n_in=dim*5, n_out=2, n_hidden=100, y=y, n_tokens=len(txt), dim=dim)
and then I use my input (x) as follows:
W = numpy.asarray(
rng.uniform(low=0., high=1., size=(n_tokens, dim)),
dtype=theano.config.floatX
)
self.W = theano.shared(value=W, name='W', borrow=True)
self.output = W[x, ]
The intention is that at run time x will be a simple vector of indices of the form
x = [0, 1, 5, 98....]
Thanks for the help
Upvotes: 0
Views: 466
Reputation: 1018
You may be able to use inc_subtensor
or set_subtensor
for this type of behavior, instead of slicing. See http://deeplearning.net/software/theano/library/tensor/basic.html#theano.tensor.set_subtensor for more details.
Upvotes: 0
Reputation: 195
The matrix W is of numpy ndarray type, so it does not know how to deal with Theano tensors such as x. If you want to index this numpy array, use a numpy index array instead of a Theano tensor. If you want to index the Theano tensor self.W, you will have to wait for the next release of Theano, or update to the development version: the theano manual says that:
Like NumPy, Theano distinguishes between basic and advanced indexing. Theano fully supports basic indexing (see NumPy’s indexing).
Integer advanced indexing will be supported in 0.6rc4 (or the development version). We do not support boolean masks, as Theano does not have a boolean type (we use int8 for the output of logic operators).
Upvotes: 1