我将尝试在给定布尔值的情况下获取向量的最大值。
使用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'
为什么会发生这种情况?这是我忽略的微妙细节吗?
nonzero()
方法/属性,因此你不能像使用numpy数组那样使用它。 - Jeff Tratnertheano.version.version
给我的回复是'0.6.0rc3'
。在这个版本中不支持nonzero()
吗? - Noob Saibot