Skip to content
Advertisement

How to use tf.repeat() to replicate a specific column/row/slice?

this thread explains well the use of tf.repeat() as a tensorflow alternative to np.repeat(). one functionality which I was unable to figure out, in np.repeat(), a specific column/row/slice can be replicated by supplying the index. e.g.

JavaScript

is there any tensorflow alternative to this functionality of np.repeat()?

Advertisement

Answer

You could use the repeats parameter of tf.repeat:

JavaScript
JavaScript

where you get the first row in the tensor once, and the second row twice.

Or you could use tf.concat with tf.repeat:

JavaScript

Tensorflow 1.14.0 solution:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement