logical_and¶
-
paddle.fluid.layers.
logical_and
(x, y, out=None, name=None)[source] logical_and Operator
It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor. Each element of Out is calculated by
\[Out = X \land Y\]- Parameters
x (Variable) – Left hand operand of logical_and operator. Must be a LoDTensor or Tensor of type bool
y (Variable) – Right hand operand of logical_and operator. Must be a LoDTensor or Tensor of type bool
out (LoDTensor or Tensor) – The LoDTensor or 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
- Returns
n-dim bool LoDTensor or Tensor
- Return type
Variable
Examples
import paddle.fluid as fluid import numpy as np # Graph organizing x = fluid.layers.data(name='x', shape=[2], dtype='bool') y = fluid.layers.data(name='y', shape=[2], dtype='bool') res = fluid.layers.logical_and(x=x, y=y) # The comment lists another available method. # res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0) # fluid.layers.logical_and(x=x, y=y, out=res) # Create an executor using CPU as an example exe = fluid.Executor(fluid.CPUPlace()) # Execute x_i = np.array([[1, 0], [0, 1]]).astype(np.bool) y_i = np.array([[1, 1], [0, 0]]).astype(np.bool) res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[res]) print(res_val) # [[True, False], [False, False]]