估算张量(Tensor.eval)与执行操作(Operation.run)

import tensorflow as tf
#创建数据流图:y = Wx + b,其中,W和B为存储节点,x为数据节点
x = tf.placeholder(tf.float32)
W = tf.Variable(1.0)
b = tf.Variable(1.0)
y = W
x + b
with tf.Session() as sess:
tf.global_variables_initializer().run() #Operation.run
fetch = y.eval(feed_dict = {x:3.0}) #Tensor.eval
print(fetch)Tensor.eval #fetch = 1.0*3.0+1

发布了113 篇原创文章 · 获赞 51 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/97173676