Felch ::在會話裏能夠執行多個 op ,ui
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 spa
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.]