tf.transpose 函数
官网介绍 https://www.tensorflow.org/api_docs/python/tf/transpose
tf.transpose(a,perm=None,name='transpose',conjugate=False
)
函数说明:
依据指定perm交换输入张量的不同维度
参数perm:
perm的格式:[0,2,1] 代表原来的纬度0,1,2要交换后的位置 [0, 2, 1] 就是 1和2纬度交换
当没有指定perm的值时候,默认是张量的最后一个纬度和第一个纬度交换,当张量为二维矩阵的时候,就是矩阵的转置
例子:
sess = tf.InteractiveSession()A = [[[1, 2, 3], [4, 5, 6]],[[7, 8, 9], [10, 11, 12]],[[13, 18, 19], [20, 21, 22]]]x = tf.transpose(A)print sess.run(x)
输出:
[[[ 1 7 13]
[ 4 10 20]]
[[ 2 8 18]
[ 5 11 21]]
[[ 3 9 19]
[ 6 12 22]]]
参数conjugate
如果设置True,则数学意义上等同于tf.conj(tf.transpose(input))