函数定义
tf.transpose(input, [dimension_1, dimenaion_2,…,dimension_n])
这个函数的主要功能是交换张量的不同维度,dimension_n是表示维度的整数,例如二维是[0,1],三维是[0,1,2],那么[2,1,0]的意思就是把输入张量的第一维度和第三维度交换。
例子
import tensorflow as tf
import numpy as np
A = np.array([[1,2,3],[4,5,6]])
a1 = tf.transpose(A,[1,0])
with tf.Session() as sess:
print(A)
print(sess.run(a1))
输出
[[1 2 3]
[4 5 6]]
[[1 4]
[2 5]
[3 6]]
Process finished with exit code 0