【发布时间】:2018-12-06 16:58:47
【问题描述】:
我正在尝试模仿 TensorFlow 中 numpy 的以下行为。
z = np.zeros(2 * 10 - 1, dtype=np.float32)
z[[2,10]] = 1
我有什么
test = tf.Variable(tf.zeros(2 * 10 - 1, dtype=tf.float32))
test[tf.constant([2,10])].assign(1)
我需要变量,因此不能只使用常量零。
尝试此操作时出现错误
InvalidArgumentError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [19], [1,2], [1,2], [1].
但这没有意义,因为我提供的索引是 1 级的,并且由于某种原因它被重新调整。
我将如何模仿上述行为?
【问题讨论】:
-
我认为this answer 可能是你要找的东西
-
不完全是(我之前说过“一流”),但意识到这并不能解决问题。因为值一次更新一个索引。将不得不使用分散更新。我认为
标签: python tensorflow