use*_*922 3 python neural-network deep-learning tensorflow
我想用值0更新2D张量中的索引。所以数据是2D张量,其第二行第二列索引值将被0代替。但是,我遇到类型错误。有人可以帮我吗?
TypeError:“ ScatterUpdate”操作的输入“ ref”需要输入左值
data = tf.Variable([[1,2,3,4,5], [6,7,8,9,0], [1,2,3,4,5]])
data2 = tf.reshape(data, [-1])
sparse_update = tf.scatter_update(data2, tf.constant([7]), tf.constant([0]))
#data = tf.reshape(data, [N,S])
init_op = tf.initialize_all_variables()
sess = tf.Session()
sess.run([init_op])
print "Values before:", sess.run([data])
#sess.run([updated_data_subset])
print "Values after:", sess.run([sparse_update])
Run Code Online (Sandbox Code Playgroud)
分散更新仅适用于变量。而是尝试这种模式。
Tensorflow版本<1.0:
a = tf.concat(0, [a[:i], [updated_value], a[i+1:]])
Tensorflow版本> = 1.0:
a = tf.concat(axis=0, values=[a[:i], [updated_value], a[i+1:]])
| 归档时间: |
|
| 查看次数: |
4866 次 |
| 最近记录: |