tf.transpose(
a,
perm=None,
name='transpose',
conjugate=False
)
返回的张量的维度i将对应于输入维度 perm[i]
。如果perm
没有给出,则设置为(n-1 ... 0),其中n是输入张量的等级。因此,默认情况下,此操作在2-D输入张量上执行常规矩阵转置。如conjugate是TRUE并且 a.dtype
是complex64
或者complex128
然后返回a
共轭和转置的值。
<span style="color:#37474f"><code>x = tf.constant([[<span style="color:#c53929">1</span> + <span style="color:#c53929">1j</span>, <span style="color:#c53929">2</span> + <span style="color:#c53929">2j</span>, <span style="color:#c53929">3</span> + <span style="color:#c53929">3j</span>],
[<span style="color:#c53929">4</span> + <span style="color:#c53929">4j</span>, <span style="color:#c53929">5</span> + <span style="color:#c53929">5j</span>, <span style="color:#c53929">6</span> + <span style="color:#c53929">6j</span>]])
tf.transpose(x, conjugate=<span style="color:#3b78e7">True</span>) <span style="color:#d81b60"># [[1 - 1j, 4 - 4j],</span>
<span style="color:#d81b60"># [2 - 2j, 5 - 5j],</span>
<span style="color:#d81b60"># [3 - 3j, 6 - 6j]]</span></code></span>
x = tf.constant([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 7, 8, 9],
[10, 11, 12]]])
# Take the transpose of the matrices in dimension-0
# (this common operation has a shorthand `linalg.transpose`)
tf.transpose(x, perm=[0, 2, 1]) # [[[1, 4],
# [2, 5],
# [3, 6]],
# [[7, 10],
# [8, 11],
# [9, 12]]]
perm参数如果默认,二维就是转置,像例子中,交换两个唯度就是把两个唯度的数字互换。
高维度即最外面那层排最前面,为0维度。