不占位的话,每进行一次Session()运算,系统就会来回运行倒腾,压力大。
占位符函数placeholder(dtype, shape=None,name=None),表示提前告知系统我占个内存,就告诉你一声,
回头赋值数据了,系统就不用再来回运算,以此提高运算速度,
大概是这个意思。
先创建一个placeholder对象,调用的时候通过feed_dict把值传过去
import tensorflow as tf
input1 = tf.placeholder(tf.float32) #占位符函数(tf.float32表示数据类型,其他参数参考上)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1,input2)
with tf.Session() as sess: #调用run
print(sess.run(output,feed_dict={input1:[6.],input2:[3.]})) #以feed_dict的形式赋值数据