KLee
KLee

Reputation: 3

Can get combined tuple tensor using tf.concat?

I'm apparently novice to tensorflow and trying to make new tensor using two existing tensors.

Let's say there are two tensors t1 and t2.

t1 = [1, 2, 3, 4, 5, 6]
t2 = [7, 8, 9, 10, 11, 12]

Is there anyway I can get new tensor t3 shaped like as following using tf.concat?

t3 = [(1,7),(2,8),(3,9),(4,10),(5,11),(6,12)]

So the first item in the first tensor combined with the first item in the second tensor and converted combined item as a tuple.

Upvotes: 0

Views: 1546

Answers (1)

James
James

Reputation: 2711

Can I suggest tf.stack instead?

tf.stack((t1, t2), axis=1)

If you're set on using tf.concat, you could expand to an extra dimension ahead of time?

tf.concat((tf.expand_dims(t1, 1), tf.expand_dims(t2, 1)), axis=1)

But tf.stack is quite a bit cleaner.

Upvotes: 1

Related Questions