我就废话不多说,咱直接看代码吧!

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 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 = 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' is more useful for n-dimensional tensors, for n > 2

x = tf.constant([[[ 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的转置是根据 perm 的设定值来进行的。

返回数组的 dimension(尺寸、维度) i与输入的 perm[i]的维度相一致。如果未给定perm,默认设置为 (n-1…0),这里的 n 值是输入变量的 rank 。因此默认情况下,这个操作执行了一个正规(regular)的2维矩形的转置

例如:

x = [[1 2 3]

[4 5 6]]

tf.transpose(x) ==> [[1 4]

[2 5]

[3 6]]

tf.transpose(x) 等价于:

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

[10, 11, 12]]])

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, 10]],

[[ 2, 8],

[ 5, 11]],

[[ 3, 9],

[ 6, 12]]])

x=tf.transpose(a,[1,2,0])

array([[[ 1, 7],

[ 2, 8],

[ 3, 9]],

[[ 4, 10],

[ 5, 11],

[ 6, 12]]])

以上这篇Tensorflow:转置函数 transpose的使用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

本文标题: Tensorflow:转置函数 transpose的使用详解

本文地址: http://www.cppcns.com/jiaoben/python/300150.html

python中transpose函数_Tensorflow:转置函数 transpose的使用详解相关推荐

  1. python实现单例模式的几种方式_基于Python中单例模式的几种实现方式及优化详解...

    单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...

  2. Python中常见的__init__.py是什么意思?详解Python import的方式和原理

    Python中常见的__init__.py是什么意思?详解Python import的方式和原理 1 什么是模块化编程? 2 __init__.py文件的作用 3 Python如何import第三方库 ...

  3. python什么意思k_对python中的*args与**kwgs的含义与作用详解

    对python中的*args与**kwgs的含义与作用详解 在定义函数的时候参数通常会使用 *args与**kwgs,形参与实参的区别不再赘述,我们来解释一下这两个的作用. *args是非关键字参数, ...

  4. args在python中什么意思_对python中的*args与**kwgs的含义与作用详解

    在定义函数的时候参数通常会使用 *args与**kwgs,形参与实参的区别不再赘述,我们来解释一下这两个的作用. *args是非关键字参数,用于元组,**kw是关键字参数 例如下面的代码 def fo ...

  5. python2.7除法_对python中的float除法和整除法的实例详解

    从python2.2开始,便有两种除法运算符:"/"."//".两者最大区别在: python2.2前的版本和python2.2以后3.0以前的版本的默认情况下 ...

  6. python中怎么计数_浅谈python中统计计数的几种方法和Counter详解

    1) 使用字典dict() 循环遍历出一个可迭代对象中的元素,如果字典没有该元素,那么就让该元素作为字典的键,并将该键赋值为1,如果存在就将该元素对应的值加1. lists = ['a','a','b ...

  7. python transpose函数_Tensorflow:转置函数transpose的使用详解

    我就废话不多说,咱直接看代码吧! tf.transpose transpose( a, perm=None, name='transpose' ) Defined in tensorflow/pyth ...

  8. 在python中等号前面与后面分别是什么意思-python中is与双等于号“==”的区别示例详解...

    前言 在开始本文之前,首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识).python type()(数据类型)和value(值).is和==都是对对象进行比较判断作用的,但对对 ...

  9. python中定制类_python定制类__str__(实例详解)

    在接下来的文章中,让我们明白什么是python中的自定义类.学习什么是python的自定义类,python定制类可以扮演何种角色在python编程.当你看到像__xxx__ __slots__变量或函 ...

最新文章

  1. Java8 - 接口默认方法
  2. linux 7 zip软件下载,linux安装使用7zip教程
  3. C++ 获取文件大小
  4. 【RAC】 RAC For W2K8R2 安装--总体规划 (一)
  5. 简单易学的深度学习算法:Wide Deep Learning
  6. WPF 实现图片切成九宫格控件~
  7. Python selenium web UI之Chrome 与 Chromedriver对应版本映射表及下载地址和配置(windows, Mac OS)...
  8. 在Hibernate的session中同时有两个相同id的同类型对象,修改失败
  9. leetcode172. 阶乘后的零 最快算法
  10. linux 嵌入式 快照_Linux 系统之Systemd
  11. linux控制流程,Linux - Bash - 流程控制
  12. php study 直接显示代码_《细说PHP》第四版 样章 第18章 数据库抽象层PDO 12
  13. mysql外连接基准表_4.mysql数据库创建,表创建模等模板脚本,mysql_SQL99标准的连接查询(内连接,外连接,满外连接,交叉连接)...
  14. linux 内核之美,Linux内核 | 系统调用
  15. springboot+freemarker毕业设计项目错误合集
  16. 《Web漏洞防护》读书笔记——第2章,SQL注入防护
  17. vs2008 sp1 C++ 发布程序
  18. 宇视科技的录像机添加海康的摄像头提示用户名或密码错误
  19. HDU4565 So Easy!【矩阵快速幂】
  20. 免Root–获取WIFI密码

热门文章

  1. 三维向量的简单运算(点积、叉积及点到直线的距离)
  2. 运动戴什么耳机好,推荐五款无线运动蓝牙耳机
  3. Microphone回音问题分析
  4. Matplotlib之3D图像
  5. Matlab消除异常值,从matlab boxplot中删除某些异常值
  6. MySQL数据库:第五章:常见函数
  7. 学python能干嘛-学Python后到底能干什么
  8. 一些想说的话,无关技术
  9. html5 offsetx,原生HTML5关于Div对象的.clientLeft、.offsetLeft、.clientX、.offsetX区分
  10. Springboot+ssm企业员工考勤管理系统