Theano tensor slicing… how to use boolean to slice?
In numpy, if I have a boolean array, I can use it to select elements of another array: >>> import numpy as np >>> x = np.array([1, 2, 3]) >>> idx = np.array([True, False, True]) >>> x[idx] array([1, 3]) I need to do this in theano. This is what I tried, but I got an unexpected result. >>> from theano import tensor as T >>> x = T.vector() >>> idx = T.ivector() >>> y = x[idx] >>> y.eval({x: np.array([1,2,3]), idx: np.array([True, False, True])}) array([ 2., 1., 2.]) Can someone explain the theano result and suggest how to get the numpy result? I need to know how to do this in order to properly