transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.python
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joininggit
Transposes a
. Permutes the dimensions according to perm
.github
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.api
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]]]
a
: A Tensor
.perm
: A permutation of the dimensions of a
.name
: A name for the operation (optional).A transposed Tensor
.ide
2、中文翻譯函數
transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.ui
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joiningthis
a的轉置是根據 perm 的設定值來進行的。 spa
返回數組的 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
:操做的名稱(可選).
返回的是一個轉置的張量。
3、解釋
tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):這個函數主要適用於交換輸入張量的不一樣維度用的,若是輸入張量是二維,就至關是轉置。dimension_n是整數,若是張量是三維,就是用0,1,2來表示。這個列表裏的每一個數對應相應的維度。若是是[2,1,0],就把輸入張量的第三維度和第一維度交換。