我正在使用Tensorflow的scatter_update在簡單測試中設置數組的值。我期望以下代碼將數組中的所有值設置爲1.0。Tensorflow增量分配與scatter_update不一致結果
pt = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
numOne = tf.constant(1)
xi = tf.Variable(0)
out = tf.Variable(pt)
tf.global_variables_initializer().run()
xi_ = xi + numOne
out_ = tf.scatter_update(out, [xi], [tf.cast(numOne, tf.float32)])
step = tf.group(
xi.assign(xi_),
out.assign(out_)
)
for i in range(15): step.run()
print(out.eval())
相反,我得到這樣的結果不一致:
[ 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1. 1.]
是否有某種類型的鎖,我很想念機制呢?
除了16,並且你期望填充15個值,我認爲隨着操作執行的隨機順序發生了一些事情。 – Uvar