paddle.fluid.layers.logical_not(x, out=None, name=None)[source]

logical_not Operator

It operates element-wise on X, and returns the Out. X and Out are N-dim boolean LoDTensor or Tensor. Each element of Out is calculated by

\[Out = \lnot X\]
  • x (Variable) – Operand of logical_not operator. Must be a LoDTensor or Tensor of type bool

  • out (LoDTensor/Tensor) – The LoDTensor/Tensor that specifies the output of the operator, which can be any Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output.

  • name (str|None) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name


n-dim bool LoDTensor or Tensor

Return type



import paddle.fluid as fluid
import numpy as np

# Graph organizing
x = fluid.layers.data(name='x', shape=[2], dtype='bool')
res = fluid.layers.logical_not(x)
# The comment lists another availble method.
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0)
# fluid.layers.logical_not(x, out=res)

# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())

# Execute
x_i = np.array([[1, 0]]).astype(np.bool)
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i}, fetch_list=[res])
print(res_val) # [[False, True]]