tensorflow-占位符
#重點
1、fetch:指run運行多個op
2、feed:運行的時候以字典的形式傳參,參數(shù)名作為key:value
import tensorflow as tf
#fetch:就是同時運行多個op的意思
input1 = tf.constant(3.0)
input2 = tf.constant(4.0)
input3 = tf.constant(5.0)
#加法
add = tf.add(input2,input3)
#乘法
mul = tf.multiply(input1,add)
with tf.Session() as ss:
result = ss.run([mul,add])
print(result)
#結(jié)果:
[27.0, 9.0]
#feed:創(chuàng)建占位符,運行的時候,以字典的形式傳入對應參數(shù)的數(shù)據(jù),用參數(shù)名作為key:value
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1,input2)
with tf.Session() as sss:
#feed的數(shù)據(jù)以字典的形式傳入
print(sss.run(output,feed_dict={input1:[2.0],input2:[3.0]}))
#結(jié)果:
[6.]