如何用另一个张量的值替换 Tensorflow 张量中的某些值? [英] How to replace certain values in Tensorflow tensor with the values of the other tensor?
本文介绍了如何用另一个张量的值替换 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!
这篇关于如何用另一个张量的值替换 Tensorflow 张量中的某些值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文