火炬中ByteTensor的逻辑否定

时间:2016-04-04 15:42:23

标签: lua logical-operators torch

是否有办法在火炬的ByteTensor上采取逻辑否定(即执行NOT操作):

th> a = torch.rand(4)

th> a
 0.5786
 0.5271
 0.0090
 0.8859
[torch.DoubleTensor of size 4]

th> b = a:le(0.5)

th> a[b]
0.001 *
 9.0080
[torch.DoubleTensor of size 1]

th> -- How to select all "other" elements of a?
th> -- a[~b] or a[!b] or a[b:neg()] don't work.

1 个答案:

答案 0 :(得分:1)

通过torch.ne(不相等):

 a[b:ne(1)]

修改

或等效地通过torch.eq

 a[b:eq(0)]