Home > Back-end >  Alternative to tf.parallel_stack() for eager execution
Alternative to tf.parallel_stack() for eager execution

Time:11-14

I'd like to use tf.parallel_stack() for a data operation inside an eagerly-compiled model, but it seems that tf.parallel_stack() doesn't support eager execution. I'm therefore looking for alternative function(s) achieving the same result.

Below is a small example of the required result:

x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])

# Wanted result:
tf.parallel_stack([x, y, z])  # [[1, 4], [2, 5], [3, 6]]

I tried tf.concat(), but I'd still need to convert the resulting 1D vector into a 2-dimensional one as above.

tf.concat((x, y, z), axis = 0) # [1, 4, 2, 5, 3, 6] 

CodePudding user response:

Maybe try adding a new dimension:

tf.concat((x[None, ...], y[None, ...], z[None, ...]), axis = 0)
  • Related