tf.transpose()的用法


一、tensorflow官方文檔內容

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

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

See the guides: Math > Matrix Math FunctionsTensor 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: A Tensor.
  • perm: A permutation of the dimensions of a.
  • 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 FunctionsTensor 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],就把輸入張量的第三維度和第一維度交換。  

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM