我爱编程

tensorflow-占位符

2018-03-07  本文已影响0人  东岳哥哥

tensorflow-占位符

#重点
1、fetch:指run运行多个op
2、feed:运行的时候以字典的形式传参,参数名作为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)
#结果: 
    [27.0, 9.0]
#feed:创建占位符,运行的时候,以字典的形式传入对应参数的数据,用参数名作为key:value
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

output = tf.multiply(input1,input2)

with tf.Session() as sss:
    #feed的数据以字典的形式传入
    print(sss.run(output,feed_dict={input1:[2.0],input2:[3.0]}))
#结果: 
[6.]
上一篇 下一篇

猜你喜欢

热点阅读