我想更新 3 维张量的切片。下列的如何在 Tensorflow 中进行切片分配 https://stackoverflow.com/questions/39157723/how-to-do-slice-assignment-in-tensorflow/43139565#43139565我会做类似的事情
import tensorflow as tf
with tf.Session() as sess:
init_val = tf.Variable(tf.zeros((2, 3, 3)))
indices = tf.constant([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1]])
update = tf.scatter_nd_add(init_val, indices, tf.ones(4))
init = tf.global_variables_initializer()
sess.run(init)
print(sess.run(update))
这是可行的,但由于我的实际问题更复杂,我想通过定义切片的开头和大小来以某种方式自动生成索引集,例如您是否会使用tf.slice(...)
。你有什么想法?提前致谢!
我使用的是 TensorFlow 1.12,这是目前最新的版本。