想要创建一个映射函数' key-to-function'在theano(提供从预定义的有限集给出一些数字的函数); 最小崩溃示例不起作用。
x = T.lscalar()
indices_array = theano.shared(numpy.asarray(range(2)))
default_function = theano.function([x], x)
values_array = theano.shared(numpy.asarray([theano.function([x], 2 * x), theano.function([x], x * x)])) # BANG!
mapping = T.switch(T.eq(indices_array, -1), default_function, values_array[indices_array])
这里的堆栈跟踪:
Traceback (most recent call last):
File ".../theano_sandbox.py", line xxx, in <module>
a = T.switch(T.eq(indices_array, -1), default_function, values_array[indices_array])
File "/usr/local/lib/python2.7/dist-packages/theano/compile/sharedvalue.py", line 144, in __getitem__
"This shared variable contains %s" % msg)
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.
在theano中有可能吗?