tensorflow-占位符

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.]
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容