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 , []]])