Home > Software engineering >  How to get specific index (Column) in Tensors and merge them using TensorFlow
How to get specific index (Column) in Tensors and merge them using TensorFlow

Time:04-15

I am trying to write a model and have two input tensors of shape = (None, 8, 384) and I need to select them based on index in their second position and combine them to get eight tensors of size (None, 2, 384).

For example, suppose T1 has a size of (None, 8, 384), which corresponds to the first variable with 8 cities and 384 days. T2 has a size of (None, 8, 384), which corresponds to the second variable with 8 cities and 384 days. I want to select the first city (None, 1, 348) from both T1 and T2 and combine them to make a new tensor of size (None, 2, 384).

CodePudding user response:

column_indices = tf.concat([tf.gather(T1, [0], axis=1),tf.gather(T2, [0], axis=1)], axis=1)

  • Related