0

I have a list :

my_list = [[1,2,3,4], [4,5,6], [1,2,1,2,1,2]]

I also have a tensor variable:

a_tensor = theano.tensor.ivector("tensor")

now I want to use theano.scan to get the corresponding item in the list given the index:

result, _ = theano.scan(fn=lambda idx, a_list:a_list[idx],
                        sequences=[a_tensor], 
                        non_sequences=theano.shared(np.array(my_list)))    

but got the error: *TypeError: The generic 'SharedVariable' object is not subscriptable. This shared variable contains a Numpy array with dtype: 'object'. This data type is not currently recognized by Theano tensors: please cast your data into a supported numeric type if you need Theano tensor functionalities. *

I'm very new to Theano so I'm probably thinking about this problem in the wrong way. I would really appreciate any advice.

Hungry fool
  • 27
  • 1
  • 6

1 Answers1

0

In the error message,

TypeError: The generic 'SharedVariable' object is not subscriptable. This shared variable contains a Numpy array with dtype: 'object'. This data type is not currently recognized by Theano tensors: please cast your data into a supported numeric type if you need Theano tensor functionalities.

The shared variable passed to theano.scan as non_sequences is not properly defined. This is because np.array(my_list) returns a array of which dtype is object, not integer. That's because my_list has irregular shape.

With

my_list = [1,2,3,4]

, your code would work.

codebomb
  • 260
  • 3
  • 11