paddlepaddle学习笔记(2)control flow控制流之if else判断

一、代码

from paddle import fluid
a = fluid.layers.fill_constant(shape=[2,1],dtype='int64',value=5)
b= fluid.layers.fill_constant(shape=[2,1],dtype='int64',value=6)
ifcond = fluid.layers.less_than(x=a,y=b)#是否a<b的判断
ie = fluid.layers.IfElse(ifcond)#IfElse执行这个判断,如果正确则执行。这里a是小于b的
with ie.true_block():  #以下几行代码实际上就是把a加1,然后输出
    c = ie.input(a)
    c+=1
    ie.output(c)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_main_program(),fetch_list=[c])

二、执行结果

猜你喜欢

转载自blog.csdn.net/Johnisjohn/article/details/89706648