佔位符:數據結構
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf ''' TensorFlow中的佔位符placeholder 佔位符是一種特殊的數據結構,相似動態變量 Feed提交數據,Fetch提取數據 ''' a = tf.placeholder(tf.float32,name="a") b = tf.placeholder(tf.float32,name="b") c = tf.multiply(a,b,name="c") d = tf.subtract(a,b,name="d") #變量初始化操做 init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) #經過feed_dict的參數傳值,按字典格式 rc,rd = sess.run([c,d],feed_dict={a:[8.0,2.0,3.5],b:[1.5,2.0,4.]}) print("value of c = ",rd,"value of d = ",rd)