tensorflow基础教程(二)

tensorflow基础教程(二)

Fetch与Feed的区别

1.Fetch:

可以同时运行两个op

import tensorflow as tf


#定义常量
input1 = tf.constant(3.0)
input2 = tf.constant(4.0)
input3 = tf.constant(5.0)

#增加一个加法op
add = tf.add(input1,input2)
#增加一个乘法op
mul = tf.multiply(input2,input3)

#建立会话
with tf.Session() as sess:
    result = sess.run([mul,add])    #同时运行add与mul两个op
    print(result)

结果为:

[20.0, 7.0] 

2.Feed

定义占位符最后再传值

import tensorflow as tf

#创建占位符
input1 = tf.placeholder(tf.float64)
input2 = tf.placeholder(tf.float64)

#创建一个乘法
output = tf.multiply(input1,input1)

with tf.Session() as sess:
    print(sess.run(output,feed_dict={input1:[7.0],input2:[8.0]}))   #Feed通过字典给output传值
    

结果为: 

结果:
[49.]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值