W = tf.Variable(tf.zeros([1]))
我从上面的陈述中了解到,每次为W运行tensorflow会话时,我都会获得值0。
例如: 如果我运行:
W = tf.Variable(tf.zeros([1]))
with tf.Session() as sess:
sess.run(W.initializer)
print(sess.run(W))
我得到输出0。
但是,如果我运行:
with tf.name_scope("LinearRegression") as scope:
W = tf.Variable(tf.zeros([1])) #we are generating a random point using a different strategy and storing in w
b = tf.Variable(tf.zeros([1])) #we are generating a random point using a different strategy and storing in b
y = W * x_data + b
for i in range(6):
sess.run(train)
print(i, sess.run(W), sess.run(b), sess.run(loss))
plt.plot(x_data, y_data, 'ro', label='Original data')
plt.plot(x_data, sess.run(W)*x_data + sess.run(b))
我得到不同的W值。
这怎么可能使我无处为W赋值,然后每次都获得W的随机值。例如
[0.09564029] [0.38026553] 0.002828496
上面提供的..如果需要,将发布完整的代码
预计是每次打印0