To get an intuitive understanding about this function, you can execute following code and check the result
import tensorflow as tf
v1 = tf.constant([[[0, 1, 3, 5],[2, 3, 4, 5]], [[5, 6, 7, 8], [9, 10, 11, 12]]], name='Data')
result = tf.transpose(v1, perm=[0, 1, 2])
result_1 = tf.transpose(v1, perm=[0, 2, 1])
result_2 = tf.transpose(v1, perm=[1, 0, 2])
result_3 = tf.transpose(v1, perm=[2, 0, 1])
with tf.Session() as sess:
print (sess.run(result))
print (sess.run(result_1))
print (sess.run(result_2))
print (sess.run(result_3))
If the tensor is a 2D tensor, you can think this operation is a matrix transposition, but you should forget matrix transposition when it comes to higher dimension. In higher dimension case, it is more like a reshape operation plus a re position.
The most straight forward way to understand it is, first this function defines shape of transposed tensor by just rearranging each element of original shape. For example, we have a tensor whose shape is (2, 2, 4), perm is (2, 0, 1) , so we pick shape[2] first, then we pick shape[0] , then we pick shape[1], so we get a new tensor whose shape is (4, 2, 2).
Next step, each element's coordinate is changed according to perm too. For example, coordinate of number 9 is (1, 1, 0), its new coordinate should be (0, 1, 1)