less_than

paddle.fluid.layers. less_than ( x, y, force_cpu=None, cond=None, name=None ) [源代码]

该OP逐元素地返回

less_than - 图1

的逻辑值,使用重载算子 < 可以有相同的计算函数效果

参数:

  • x (Variable) - 进行比较的第一个输入,是一个多维的LoDTensor/Tensor,数据类型可以是float32,float64,int32,int64。

  • y (Variable) - 进行比较的第二个输入,是一个多维的LoDTensor/Tensor,数据类型可以是float32,float64,int32,int64。

  • force_cpu (bool) – 如果为True则强制将输出变量写入CPU内存中,否则将其写入目前所在的运算设备上。默认值为False。注意:该属性已弃用,其值始终是False。

  • cond (Variable,可选) – 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。

  • name (str,可选)- 具体用法请参见 Name ,一般无需设置,默认值为None。

返回:输出结果的LoDTensor/Tensor,数据的shape和输入x一致。

返回类型: Variable,数据类型为bool。

代码示例:

  1. import paddle.fluid as fluid
  2. import numpy as np
  3. # Graph Organizing
  4. x = fluid.layers.data(name='x', shape=[2], dtype='float64')
  5. y = fluid.layers.data(name='y', shape=[2], dtype='float64')
  6. result = fluid.layers.less_than(x=x, y=y)
  7. # The comment lists another available method.
  8. # result = fluid.layers.fill_constant(shape=[2], dtype='float64', value=0)
  9. # fluid.layers.less_than(x=x, y=y, cond=result)
  10. # Create an executor using CPU as example
  11. exe = fluid.Executor(fluid.CPUPlace())
  12. exe.run(fluid.default_startup_program())
  13. # Execute
  14. x_i = np.array([[1, 2], [3, 4]]).astype(np.float64)
  15. y_i = np.array([[2, 2], [1, 3]]).astype(np.float64)
  16. result_value, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[result])
  17. print(result_value) # [[True, False], [False, False]]