Fetch and Feed

import tensorflow as tf
# Fetch
input1 = tf.constant(2)
input2 = tf.constant(3)
input3 = tf.constant(4)

add = tf.add(input1, input2)
# 点乘
mul = tf.multiply(add, input3)

with tf.Session() as sess:
    print(sess.run([add, mul]))
import tensorflow as tf
# Feed
# 定义占位符
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
# 点乘
output = tf.multiply(input1, input2)
# 定义会话
with tf.Session() as sess:
    # feed的形式以字典传入,传入时是可变类型list,输出时也是list
    print(sess.run(output, feed_dict={input1: 4, input2: 5}))

你可能感兴趣的:(tensorflow)