通过placeholder指定占位符变量,并在运行时指定数据具体值
import tensorflow as tf
# 定义占位符
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
# 定义操作
add = tf.add(a, b)
with tf.Session() as sess:
# 执行操作并指定运算变量
add_result = sess.run(add, feed_dict={a: 2, b: 3})
print(add_result)