paddle.fluid.layers.control_flow. equal ( x, y, cond=None, name=None ) [source]

This layer returns the truth value of \(x == y\) elementwise.

  • x (Variable) – Tensor, data type is float32, float64, int32, int64.

  • y (Variable) – Tensor, data type is float32, float64, int32, int64.

  • cond (Variable, optional) – Optional output which can be any created Variable that meets the requirements to store the result of equal. if cond is None, a new Varibale will be created to store the result.

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


output Tensor, it’s shape is the same as the input’s Tensor, and the data type is bool.

Return type



import paddle.fluid as fluid
import numpy as np
out_cond =fluid.data(name="input1", shape=[2], dtype='bool')
label = fluid.layers.assign(np.array([3, 3], dtype="int32"))
limit = fluid.layers.assign(np.array([3, 2], dtype="int32"))
label_cond = fluid.layers.assign(np.array([1, 2], dtype="int32"))
out1 = fluid.layers.equal(x=label,y=limit) #out1=[True, False]
out2 = fluid.layers.equal(x=label_cond,y=limit, cond=out_cond) #out2=[False, True] out_cond=[False, True]