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))