I have a 1D tensor a that I want to stack/pack/tile into a 2D tensor like y=[a, a, a]
. If I knew how many times I wanted it repeated, I could use tf.tile
along with reshape
.
But I don't because the size is dependent on the batch size. The placeholder value is None
which isn't a valid input. I know for tf.slice
one can input -1
and let tensorflow figure it out, but I don't see how tensorflow could infer the correct size. I do have a tensor x
that would be equal in shape to y
, but I don't see a tile_like
function.
Any suggestions?
You can use tf.shape
to find out the runtime shape of a tensor, and use it as the basis for the argument to tf.tile
:
import tensorflow as tf
import numpy as np
x = tf.placeholder(tf.float32, shape=[None, 3])
y = tf.tile([2, 3], tf.shape(x)[0:1])
sess = tf.Session()
print(sess.run(y, feed_dict={x: np.zeros([11, 3])}))
I verified this code works with the Tensorflow 1.0 release candidiate. Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With