tf.transpose详解(能懂版)

版权声明:如使用此博客内容,请经过作者同意,谢谢 https://blog.csdn.net/qq_40994943/article/details/85270159

看到网上大部分博客都没说清楚,就来写一篇
tf.transpose()官方例程:

def transpose(a, perm=None, name="transpose"):
  """Transposes `a`. Permutes the dimensions according to `perm`.

a:数组
perm:控制转置的操作,以perm = [0,1,2] 3个维度的数组为例, 0–代表的是最外层的一维, 1–代表外向内数第二维, 2–代表最内层的一维,这种perm是默认的值.如果换成[1,0,2],就是把最外层的两维进行转置,比如原来是2乘3乘4,经过[1,0,2]的转置维度将会变成3乘2乘4

example:

input_x = [
    [
        [1, 2, 3, 4],
        [5, 6, 7, 8],
        [9, 10, 11, 12]
    ],
    [
        [13, 14, 15, 16],
        [17, 18, 19, 20],
        [21, 22, 23, 24]
    ]

]
output1=tf.transpose(input_x,(1,0,2))
output1=

[

  [

     [ 1  2  3  4]
     [13 14 15 16]

 ]
 [

    [ 5  6  7  8]
    [17 18 19 20]

  ]
  [

     [ 9 10 11 12]
     [21 22 23 24]

  ]

]


output2=tf.transpose(input_x,(0,2,1))#变成2*4*3
 output2=[

  [

      [ 1  5  9]
      [ 2  6 10]
      [ 3  7 11]
      [ 4  8 12]

  ]

  [

     [13 17 21]
     [14 18 22]
     [15 19 23]
     [16 20 24]

  ]

]

猜你喜欢

转载自blog.csdn.net/qq_40994943/article/details/85270159
今日推荐