Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, :]
like image 900
Massyanya Avatar asked Jun 20 '17 15:06

Massyanya


People also ask

How do you transpose a tensor in TensorFlow?

transpose(x, perm=[1, 0]) . As above, simply calling tf. transpose will default to perm=[2,1,0] . To take the transpose of the matrices in dimension-0 (such as when you are transposing matrices where 0 is the batch dimension), you would set perm=[0,2,1] .

What is Value_index in tensor?

value_index. An int . Index of the operation's endpoint that produces this tensor. dtype. A DType .

Can we have multidimensional tensor?

Tensors are multi-dimensional arrays with a uniform type (called a dtype ). You can see all supported dtypes at tf. dtypes.


1 Answers

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!

like image 98
drsbhattac Avatar answered Oct 17 '22 02:10

drsbhattac