transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.python
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joininggit
Transposes a
. Permutes the dimensions according to perm
.github
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.api
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]]]
a
: A Tensor
.perm
: A permutation of the dimensions of a
.name
: A name for the operation (optional).A transposed Tensor
.ide
2、中文翻译函数
transpose( a, perm=None, name='transpose' )
Defined in tensorflow/python/ops/array_ops.py
.ui
See the guides: Math > Matrix Math Functions, Tensor Transformations > Slicing and Joiningthis
a的转置是根据 perm 的设定值来进行的。 spa
返回数组的 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
:操做的名称(可选).
返回的是一个转置的张量。
3、解释
tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):这个函数主要适用于交换输入张量的不一样维度用的,若是输入张量是二维,就至关是转置。dimension_n是整数,若是张量是三维,就是用0,1,2来表示。这个列表里的每一个数对应相应的维度。若是是[2,1,0],就把输入张量的第三维度和第一维度交换。