import tensorflow
as tf
condition
= tf
.placeholder
(tf
.int32
, name
="condition")
A
= tf
.constant
(value
=123)
B
= tf
.constant
(value
=321)
def func1():
return A
def func2():
return B
y
= tf
.cond
(condition
> 0, func1
, func2
)
sess
= tf
.Session
()
feed_dict
= {condition
:1}
print(sess
.run
(y
,feed_dict
=feed_dict
))
feed_dict
= {condition
:-1}
print(sess
.run
(y
,feed_dict
=feed_dict
))
打印结果: 123 321
转载请注明原文地址:https://ipadbbs.8miu.com/read-16086.html