How to negate the Bool type Tensor?

x = torch.tensor([False], dtype=torch.bool)
~x # error

any simple way of doing negation ?

1 Like

Iā€™m not near a PC now to test. Does not x work?

I have just tried this:


Works like a dream

However, my dtype is not bool, it is torch.uint8
Which is the default output when you do logical operation on a tensor like x>0


He should change dtype to uint8 and tilde operator will work.

1 Like

Not sure which pytorch version you have, but in 1.4, ~x works fine on torch.bool tensors.


~x does not work, however (x == False) works fine.