【发布时间】:2016-08-01 10:56:02
【问题描述】:
我有以下简单的占位符:
x = tf.placeholder(tf.float32, shape=[1])
y = tf.placeholder(tf.float32, shape=[1])
z = tf.placeholder(tf.float32, shape=[1])
有两个函数fn1和fn2定义为:
def fn1(a, b):
return tf.mul(a, b)
def fn2(a, b):
return tf.add(a, b)
现在我想根据 pred 条件计算结果:
pred = tf.placeholder(tf.bool, shape=[1])
result = tf.cond(pred, fn1(x,y), fn2(y,z))
但它给了我一个错误说fn1 and fn2 must be callable。
如何编写fn1 和fn2 以便它们可以在运行时接收参数?
我想拨打以下电话:
sess.run(result, feed_dict={x:1,y:2,z:3,pred:True})
【问题讨论】:
标签: python if-statement tensorflow