美文网首页
tf.transpose()

tf.transpose()

作者: yalesaleng | 来源:发表于2018-07-16 16:08 被阅读16次
import numpy as np
import tensorflow as tf

# x = np.array([[[1,2,3],
# [4,5,6]],
# [[7,8,9],
# [10,11,12]]])
#
# print(x.shape)

x = np.array([[1,4],
              [2,5],
              [3,6]])

y = tf.transpose(x,[1,0])

sess = tf.InteractiveSession()

print(sess.run(x))
print(sess.run(y))

>>>   [[1 2 3]
       [4 5 6]]

因为x是一个二维矩阵,
所以在tf.transpose里的第二个参数初始状态应该是[0,1]
那么[1,0]表示的就是第二维和第一维的数进行交换。


倘若:

import numpy as np
import tensorflow as tf

x = np.array([[[1,2,3],
               [4,5,6]],
              [[7,8,9],
               [10,11,12]]])

y = tf.transpose(x,[2,1,0])
x = tf.transpose(x)

sess = tf.InteractiveSession()

print(sess.run(x))
print('\n\n')
print(sess.run(y))

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

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

表示的就是将第3维和第1维的值进行交换。

相关文章

  • tf.transpose()

    因为x是一个二维矩阵,所以在tf.transpose里的第二个参数初始状态应该是[0,1]那么[1,0]表示的就是...

  • tf.transpose()

    tf.transpose()为转置函数,其中参数perm用来设置需要转置的维度和顺序 img是一个2*2*3 (r...

  • tf.transpose

    按照翻译来解释,就是转置的意思.如果把一个矩阵[[120][340]]转置,那么很好理解,就是[[13][24][...

  • tensor常用操作

    tf.transpose(): 转置, 若输入数据格式为NCHW可转化为NHWC tf.expand_dims()...

  • Understanding tf.transpose()

    To get an intuitive understanding about this function, yo...

  • TF2.0:tf.reshape与tf.transpose的区别

    说明:这两个维度变换操作,对于张量的处理是非常重要的!但是二者其实有本质上的不同!一定不能混用。本文将详细说明两者...

网友评论

      本文标题:tf.transpose()

      本文链接:https://www.haomeiwen.com/subject/mvybpftx.html