Bowen Peng
Bowen Peng

Reputation: 1825

how to repeat (2, 1) tensors to (50, 1) tensors in TensorFlow 1.10

For example,

# x is a tensor
print(x)
[1, 0] 

# after repeating it
print(x)
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

There is no tf.repeat in TensorFlow 1.10 so if there is the best replaceable way to implement it?

Upvotes: 0

Views: 151

Answers (2)

bluesummers
bluesummers

Reputation: 12607

You could go with this

import tensorflow as tf

x = tf.constant([1, 0])
temp = tf.zeros(shape=(25, 2), dtype=tf.int32)

result = tf.reshape(tf.transpose(temp + x), (-1,))

Upvotes: 1

AloneTogether
AloneTogether

Reputation: 26708

If you can really only use Tensorflow 1.10 then try something like this:

import tensorflow as tf

x = tf.constant([1, 0])
x = tf.reshape(tf.tile(tf.expand_dims(x, -1), [1, 25]), (50, 1))
print(x)

'''
tf.Tensor(
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0], shape=(50, 1), dtype=int32)
'''

Upvotes: 1

Related Questions