如何用另一个张量的值替换 Tensorflow 张量中的某些值?

问题描述:

我有一个大小为 (64, 2, 82, 1) 的 Tensorflow 张量 A,我想用张量 B 的相应部分替换它的 (:, :, 80:82, :) 部分(还有(64, 2, 82, 1) 大小).

I have a Tensorflow tensor A of size (64, 2, 82, 1), and I want to replace its (:, :, 80:82, :) part with the corresponding part of the tensor B (also (64, 2, 82, 1) size).

我该怎么做?

P.S.:准确地说,我的意思是在 numpy 中看起来像这样的操作:

P.S.: To be precise, I mean the operation that would look like this in the numpy:

A[:, :, 80:82, :] = B[:, :, 80:82, :]

以下代码可能会帮助您获得一些想法,

the following code might help you to get some idea,

a = tf.constant([[11,0,13,14],
                 [21,22,23,0]])
condition = tf.equal(a, 0)
case_true = tf.reshape(tf.multiply(tf.ones([8], tf.int32), -9999), [2, 4])
case_false = a
a_m = tf.where(condition, case_true, case_false)
sess = tf.Session()
sess.run(a_m)

这里我正在访问张量的单个元素!

here i am accessing individual element of a tensor!