0

What I want to do

M = tf.concat([tensor]*N, axix = 0) 

But now, N is a tensor that decided in run time.

other_tensor = tf.placeholder(dtype=tf.int32, shape=[None, 2])
N = tf.shape(other_tensor)[0] # N is None, and it is decided in run time.

So, how to do this?

Zehao Shi
  • 99
  • 8

1 Answers1

1

You should use tf.tile, not concat. To get the shape, use tensor.get_shape Here is an example:

import tensorflow as tf

a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([1, 2])
c = tf.tile(a, (1, int(a.get_shape()[0])))
with tf.Session() as sess:
    print sess.run(c)

If you need your tensor to have a slightly different shape, read about the second parameter in tile function and also use tf.reshape

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • Thank you for your answer. Maybe I didn't make myself clear. In my situation, a = tf.placeholder(dtype=tf.int32, shape=[None, 2]) – Zehao Shi May 25 '17 at 06:19
  • @ZehaoShi looking at your previous question, the answer is 'no, it was not clear at all'. To answer your followup question, go to the get_shape link and see what to do in case of dynamic shape – Salvador Dali May 25 '17 at 06:25
  • I use tf.shape() to get the dynamic shape. tf.tile() is exactly what I want. Thanks you very much. I'm now rewriting the question for the convenience of others. – Zehao Shi May 25 '17 at 06:31