since pytorch 1.2, there is a dtype torch.bool and associated BoolTensor. The bitwise operators aka numpy (and &, or |, xor ^ and not ~) all work on these as logical operations.
BoolTensor在pytorch1.2后引入,针对BoolTensor才有了如下逻辑运算(dtype为bool型)
- 与操作:a & b
- 或操作:a | b
- 异或操作:a ^ b
- 取反操作:~a