TensorFlow: Transpose parsing of transpose functions

Source: Internet
Author: User
Tags constant

Tf.transpose

Transpose (
    A,
    perm=none,
    name= ' transpose '
)

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

See the Guides:math > Matrix Math Functions, Tensor transformations > slicing and joining

Transposes A. Permutes the dimensions according to Perm.

The returned tensor ' s dimension I'll correspond to the input dimension perm[i]. If Perm is not a 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 = Tf.constant ([[1, 2, 3], [4, 5, 6]])
tf.transpose (x)  # [[1, 4] # [2, 5]
                 #  [3, 6]]
Tf.transpose (x, perm=[1, 0])  # [[1, 4]
                              # [  2, 5]
                              #  [3, 6]]
# ' perm ' are more useful for n-dimensional tensors, for n > 2
x = tf.constant ([[[[1,  2,  3],
                  [4,  5,  6]],
                 [[7,  8,  9],
                  [Ten, One,]]] # take the

transpose of the matrices in dimension-0
  
   tf.transpose (x, Perm=[0, 2, 1])  # [[[1,  4], # [2,  5],
                                 #   [3,  6]],
                                 # [  7, Ten],
                                 #   [8, all],
                                 #   [9, 12]]
  

The transpose of a is based on the set value of the perm.
Returns the dimension of the array (dimensions, dimensions) I and the dimensions of the input perm[i]. If Perm is not given, the default setting is (N-1 ... 0), where the n value is the rank of the input variable. So by default, this operation performs a transpose of a formal (regular) 2-D Rectangle
For example:

x = [[1 2 3] [4 5 6]] Tf.transpose (x) ==> [[1 4] [2 5]

[3 6]]
                                 Tf.transpose (x) equivalent to: Tf.transpose (x perm=[1, 0]) ==> [[1 4] [2 5] [3 6]] 
a=tf.constant ([[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]) array ([[[[[[1], 2, 3], [4, 5, 6 

       ]], [[7, 8, 9], [Ten, One,]]] x=tf.transpose (a,[1,0,2]) array ([[[1, 2, 3], [7, 8, 9],

[[4, 5, 6], [10, 11, 12]])
        X=tf.transpose (a,[0,2,1]) array ([[[[[1], 4], [2, 5], [3, 6]], [[7, 10], [8, 11], 

[9, 12]])
        X=tf.transpose (a,[2,1,0]) array ([[[[[1], 7], [4, 10]], [[2, 8], [5, 11]], [[3, 9],


[6, 12]]) Array ([[[[1], 7], [4,]], [[2, 8], [5, one]], [[3, 9], [6,]]] x=tf.tr Anspose (a,[1,2,0]) array ([[[[[1], 7], [2, 8], [3, 9]], [[4, 10], [5, 11], [6 , []]]) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.