Home > Back-end >  how to repeat (2, 1) tensors to (50, 1) tensors in TensorFlow 1.10
how to repeat (2, 1) tensors to (50, 1) tensors in TensorFlow 1.10

Time:10-27

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?
Thanks in advance.

CodePudding user response:

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(t   x), (-1,))

CodePudding user response:

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)
'''
  • Related