paddle.fluid.layers.less_than(x, y, force_cpu=None, cond=None)[source]

It operates element-wise on X and Y, and returns the Out. Each of them is a N-dim tensor. X and Y could be any type. The each element of the Out tensor is calculated by \(Out = X < Y\)

  • x (Variable) – the left hand operand of less_than operator.

  • y (Variable) – the right hand operand of less_than operator.

  • force_cpu (BOOLEAN) – Force fill output variable to cpu memory. Otherwise, fill output variable to the running device [default true].

  • cond (Variable|None) – Optional output variable to store the result of less_than


n-dim bool tensor. Each element is Out = X < Y.


import paddle.fluid as fluid
import numpy as np

# Graph Organizing
x = fluid.layers.data(name='x', shape=[2], dtype='float64')
y = fluid.layers.data(name='y', shape=[2], dtype='float64')
result = fluid.layers.less_than(x=x, y=y)
# The comment lists another available method.
# result = fluid.layers.fill_constant(shape=[2], dtype='float64', value=0)
# fluid.layers.less_than(x=x, y=y, cond=result)

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

# Execute
x_i = np.array([[1, 2], [3, 4]]).astype(np.float64)
y_i = np.array([[2, 2], [1, 3]]).astype(np.float64)
result_value, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[result])
print(result_value) # [[True, False], [False, False]]