tf.transpose()的用法

1、tensorflow官方文檔內容

transpose(
    a,
    perm=None,
    name='transpose'
)

Defined in tensorflow/python/ops/array_ops.py.python

See the guides: Math > Matrix Math FunctionsTensor 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]]]

Args:

  • a: A Tensor.
  • perm: A permutation of the dimensions of a.
  • name: A name for the operation (optional).

Returns:

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 FunctionsTensor 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],就把輸入張量的第三維度和第一維度交換。  

 
----------------------------------
參考連接:
  一、  tf.transpose函數的用法: https://i.cnblogs.com/EditPosts.aspx?opt=1
  二、 tensorflow中的不懂得知識點——轉置函數 transpose : http://blog.csdn.net/u010417185/article/details/51900441
  三、tensorflow官方文檔 https://www.tensorflow.org/versions/r1.3/api_docs/python/tf/transpose
相關文章
相關標籤/搜索