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)
Asked
Active
Viewed 1,254 times
4

Toke Faurby
- 5,788
- 9
- 41
- 62
-
did you find a better solution to this? – codekitty Feb 14 '21 at 22:58
1 Answers
2
This works, but is ugly:
tf.transpose(x, [1, 0] + [i+2 for i in range(tf.shape(x).shape[0]-2)])

Toke Faurby
- 5,788
- 9
- 41
- 62
-
2You can use `tf.rank()` instead of `tf.shape()`: `tf.transpose(x, tf.concat([[1,0], tf.range(2, tf.rank(x))], 0)` – Manolo Santos Jun 29 '17 at 12:05