fetch:可以取多个操作节点的值
import tensorflow as tf input1 =tf.constant(7.0) input2 =tf.constant(2.0) add =tf.add(input1,input2) mul =tf.multiply(add,input1) with tf.Session() as sess: result =sess.run([add,mul]) print (result)
feed:对占位符进行赋值,字典形式传入
import tensorflow as tf
input1 =tf.placeholder(tf.float32) input2 =tf.placeholder(tf.float32) mul =tf.multiply(input1,input2) with tf.Session() as sess: print (sess.run(mul,feed_dict={input1:[7.],input2:[2.]}))