Search code examples
lualogical-operatorstorch

Logical negation of ByteTensor in torch


Is there a way of taking a logical negation (i.e. performing a NOT operation) on a ByteTensor in Torch:

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.

Solution

  • Via torch.ne (not-equal):

     a[b:ne(1)]
    

    EDIT:

    Or equivalently via torch.eq:

     a[b:eq(0)]