一、tensorflow官方文檔內容
transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joining
Transposes a
. Permutes the dimensions according to perm
.
The returned tensor's dimension i will correspond to the input dimension perm[i]
. If perm
is not given, it is set to (n-1...0), where n is the rank of the input tensor. Hence by default, this operation performs a regular matrix transpose on 2-D input Tensors.
For example:
# 'x' is [[1 2 3] # [4 5 6]] tf.transpose(x) ==> [[1 4] [2 5] [3 6]] # Equivalently tf.transpose(x, perm=[1, 0]) ==> [[1 4] [2 5] [3 6]] # 'perm' is more useful for n-dimensional tensors, for n > 2 # 'x' is [[[1 2 3] # [4 5 6]] # [[7 8 9] # [10 11 12]]] # Take the transpose of the matrices in dimension-0 tf.transpose(x, perm=[0, 2, 1]) ==> [[[1 4] [2 5] [3 6]] [[7 10] [8 11] [9 12]]]
Args:
a
: ATensor
.perm
: A permutation of the dimensions ofa
.name
: A name for the operation (optional).
Returns:
A transposed Tensor
.
二、中文翻譯
transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joining
a的轉置是根據 perm 的設定值來進行的。
返回數組的 dimension(尺寸、維度) i與輸入的 perm[i]的維度相一致。如果未給定perm,默認設置為 (n-1...0),這里的 n 值是輸入變量的 rank 。因此默認情況下,這個操作執行了一個正規(regular)的2維矩形的轉置。
例子:
# 'x' is [[1 2 3] # [4 5 6]] tf.transpose(x) ==> [[1 4] [2 5] [3 6]] # Equivalently(等價於) tf.transpose(x, perm=[1, 0]) ==> [[1 4] [2 5] [3 6]] # 'perm' is more useful for n-dimensional tensors, for n > 2 # 'x' is [[[1 2 3] # [4 5 6]] # [[7 8 9] # [10 11 12]]] # Take the transpose of the matrices in dimension-0 tf.transpose(x, perm=[0, 2, 1]) ==> [[[1 4] [2 5] [3 6]] [[7 10] [8 11] [9 12]]]
參數:
a
: a 是一個張量(Tensor)perm
: perm 是 a 維度的置換name
:操作的名稱(可選).
返回值:
返回的是一個轉置的張量。
三、解釋
tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):這個函數主要適用於交換輸入張量的不同維度用的,如果輸入張量是二維,就相當是轉置。dimension_n是整數,如果張量是三維,就是用0,1,2來表示。這個列表里的每個數對應相應的維度。如果是[2,1,0],就把輸入張量的第三維度和第一維度交換。