【发布时间】:2016-12-27 23:24:02
【问题描述】:
我正在通过以下示例学习 TensorFlow:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/linear_regression.ipynb
我在下面的代码中有一个问题:
X = tf.placeholder("float")
Y = tf.placeholder("float")
# Set model weights
W = tf.Variable(rng.randn(), name="weight")
b = tf.Variable(rng.randn(), name="bias")
In [6]:
# Construct a linear model
pred = tf.add(tf.mul(X, W), b)
In [7]:
# Mean squared error
cost = tf.reduce_sum(tf.pow(pred-Y, 2))/(2*n_samples)
tf.reduce_sum 的输入是 tf.pow(pred-Y, 2)) 这似乎是一个标量(或者我错了吗?)然后我想知道为什么我们要在标量上做 reduce_sum?我在这里错过了什么?谢谢!
【问题讨论】:
标签: python-3.x tensorflow