Theano tensor slicing… how to use boolean to slice?

坚强是说给别人听的谎言 提交于 2019-12-05 18:34:24

This is not supported in theano:

We do not support boolean masks, as Theano does not have a boolean type (we use int8 for the output of logic operators).

Theano indexing with a “mask” (incorrect approach):

>>> t = theano.tensor.arange(9).reshape((3,3))
>>> t[t > 4].eval()  # an array with shape (3, 3, 3)
...

Getting a Theano result like NumPy:

>>> t[(t > 4).nonzero()].eval()
array([5, 6, 7, 8])

So you need y = x[idx.nonzero()]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!