![6d3cf348e01310be349b2a931a07ef85.png](https://i-blog.csdnimg.cn/blog_migrate/708806a9d91e75258a7b3d628a429cc0.jpeg)
今天向各位分享关于人工智能的专业技术贴,TensorFlow中张量Tensor的转置函数tf.transpose()的用法,重点介绍其参数perm及原理。原文来自我的好友,可以关注他的知乎号,李景文。
Tensor 的阶
在开始介绍转置函数之前,我们先来看一下Tensor的阶
当张量Tensor为一个标量时,即不带方向的纯量,其阶为0;
x0 = tf.constant(1)
print(x0) # 输出 tf.Tensor(1, shape=(), dtype=int32)
当Tensor为一个向量时,如[1, 2, 3]时,其阶为1;
x1 = tf.constant([1, 2, 3])
print(x1) # 输出 tf.Tensor([1 2 3], shape=(3,), dtype=int32)
当Tensor为矩阵时,其阶为2,如