我想获得给定布尔值的向量的最大值。Theano:为什么索引在这种情况下失败?
随着NumPy的:
>>> this = np.arange(10)
>>> this[~(this>=5)].max()
4
但随着Theano:
>>> that = T.arange(10, dtype='int32')
>>> that[~(that>=5)].max().eval()
9
>>> that[~(that>=5).nonzero()].max().eval()
Traceback (most recent call last):
File "<pyshell#146>", line 1, in <module>
that[~(that>=5).nonzero()].max().eval()
AttributeError: 'TensorVariable' object has no attribute 'nonzero'
为什么会出现这种情况?这是我错过的微妙的细微差别吗?
那么,对于你的第二个文字回溯是说,数组没有一个'非零()'方法/属性,所以你不能像使用numpy数组那样使用它。 –
@JeffTratner:反对网站上提供的[示例](http://deeplearning.net/software/theano/library/tensor/basic.html#indexing)... –
@NoobSailbot您是否使用了正确的版? –