Concatenate 3d Tensors By Cloning One Tensor?
I have two tensors: a = tf.placeholder(tf.float32, [None, 20, 100]) b = tf.placeholder(tf.float32, [None, 1, 100]) I want to append b to a[i, 20, 100], to create c such as c has a
Solution 1:
This can be done using tf.tile
. You will need to clone the tensor along dimension 1, 20
times to make it compatible with a
. Then a simple concatenation along dimension 2 will give you the result.
Here is the complete code,
import tensorflow as tf
a = tf.placeholder(tf.float32, [None, 20, 100])
b = tf.placeholder(tf.float32, [None, 1, 100])
c = tf.tile(b, [1,20,1])
print c.get_shape()
# Output - (?, 20, 100)
d = tf.concat(2, [a,c])
print d.get_shape()
# Output - (?, 20, 200)
Post a Comment for "Concatenate 3d Tensors By Cloning One Tensor?"