Massyanya
Massyanya

Reputation: 2934

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?

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

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

Upvotes: 14

Views: 24301

Answers (2)

drsbhattac
drsbhattac

Reputation: 119

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!

Upvotes: 8

gdelab
gdelab

Reputation: 6220

tf.assign should work: (not tested)

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

Upvotes: 0

Related Questions