今天在深度学习第四课的神经风格转移遇到了一个折磨了我很久的东西,就是高纬度矩阵转置,不得不说,一旦维度升高,真的会让人懵逼,废话不多说,开始讲一下我对TensorFlow中transpose()函数的用法。
先看一下官方API:
tf.transpose
transpose(
a, # a是一个张量
perm=None, # perm就是你对张量怎么转置的规则,即序列改变列表
name='transpose'
)
Args:
a: A Tensor.
perm: A permutation of the dimensions of a.
name: A name for the operation (optional).
Returns:
A transposed Tensor.
Transposes a. Permutes the dimensions according to perm.
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.
下面是官方给出的例子
For example:
# 'x' is [[1 2 3]
# [4 5 6]]