Faur
Faur

Reputation: 5968

Swap tensor axes in TensorFlow without tf.transpose

I have a tensor of unknown shape, but it is at least 3 dimensional, i.e. shape=[a, b, c, ...]. I would like to switch dimensions a and b, without knowing how long the tensor is (so I can't use tf.transpose, as suggested in this question)

Upvotes: 4

Views: 1300

Answers (1)

Faur
Faur

Reputation: 5968

This works, but is ugly:

tf.transpose(x, [1, 0] + [i+2 for i in range(tf.shape(x).shape[0]-2)])

Upvotes: 2

Related Questions