I need to convert a list of tensors of dimensionality N to a new tensor with dimensionality N+1 so that the new dimension would be the right most dimension.
For example if x and y would be tensors of shape (4,3) both then I am trying to create a new tensor z of shape (4,3,2) by forming z and setting tensor x as the 0th element along the third dimension and setting tensor y as the 1st element along the third dimension. In pseudocode:
z = tf.fromList([x,y],3)
What's the best way to do that in Tensorflow. I was unable to figure it out from the documentation of TF 0.7.1.
If I'm reading you correctly, you want to interleave the data of the two tensors.
You want to tf.pack()
them together, which would form a tensor of shape [2, 4, 3]
and then tf.transpose([1, 2, 0])
that resulting tensor to get to the interleaving you want.
dga's method works, but tf.pack()
has been removed from TensorFlow V1.0 onwards.
You can use tf.stack()
to achieve the same.
Docs: https://www.tensorflow.org/api_docs/python/tf/stack
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