import tensorflow as tf
# Fetch
a = tf.constant(1.0)
b = tf.constant(2.0)
c = tf.constant(3.0)
multiply = tf.multiply(a, b)
add = tf.add(matmul, c)
# Fetch可以运行多个 Op
with tf.Session() as sess:
print(sess.run([add, multiply]))
[5.0, 2.0]
# Feed
ph1 = tf.placeholder(tf.float32)
ph2 = tf.placeholder(tf.float32)
m = tf.multiply(ph1, ph2)
# 在真正执行的时候,再将数据以字典的形式传入
with tf.Session() as sess:
print(sess.run(m, feed_dict={ph1: [1.0], ph2: [2.0]}))
[ 2.]