简体   繁体   中英

How to replace certain values in Tensorflow tensor with the values of the other tensor?

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).

How would I do that?

PS: 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!

tf.assign应该工作:(未经测试)

 tf.assign(A[:, :, 80:82, :], B[:, :, 80:82, :])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM