megengine.functional.logical_not¶

logical_not(x)[源代码]

Element-wise logical NOT.

Computes the logical NOT for each element $$x_i$$ of the input tensor $$x$$.

x – input tensor. Should have a boolean data type.

a tensor containing the result of the element-wise logical NOT operation. The returned tensor must have a data type of bool.

>>> F.logical_not(True)
Tensor(False, dtype=bool, device=xpux:0)


Element-wise logical NOT:

>>> x = Tensor([True, False, True])
>>> F.logical_not(x)
Tensor([False  True False], dtype=bool, device=xpux:0)


The ~ operator can be used as a shorthand for F.logical_and on boolean tensors.

>>> ~x
Tensor([False  True False], dtype=bool, device=xpux:0)