Felch ::在会话里可以执行多个 op ,
import tensorflow as tf input1 = tf.constant(3.0) input2 = tf.constant(2.0) input3 = tf.constant(5.0) # 加法操作 add = tf.add(input2, input3) # 乘法操作 mul = tf.multiply(input1, add) with tf.Session() as sess: # d在【】中写入 上述的两个 op ,可以同时执行 res = sess.run([add, mul]) print(res)
[7.0, 21.0]
Feed
import tensorflow as tf # 创建个占位符,32位的浮点型 input1 = tf.placeholder(tf.float32) input2 = tf.placeholder(tf.float32) # 乘法操作 uitput = tf.multiply(input1, input2) with tf.Session() as sess: # Feed 的数据以字典的形式传入 print( sess.run(uitput, feed_dict={input1:[7.0], input2:[2.]}) )
[14.]