**

一 reshape函数 重排列

**

In [1]: import tensorflow as tf                                                 In [2]: a = tf.random.normal([4,28,28,3],mean=1,stddev=1)                       In [3]: a.shape
Out[3]: TensorShape([4, 28, 28, 3])In [4]: a.ndim
Out[4]: 4In [5]: tf.reshape(a,[4,28*28,3]).shape
Out[5]: TensorShape([4, 784, 3])In [6]: tf.reshape(a,[4,-1,3]).shape#未知维度时可以用-1填充
Out[6]: TensorShape([4, 784, 3])In [7]: tf.reshape(a,[4,28*28*3]).shape
Out[7]: TensorShape([4, 2352])In [8]: tf.reshape(a,[4,-1]).shape
Out[8]: TensorShape([4, 2352])
In [9]: tf.reshape(tf.reshape(a,[4,-1]),[4,28,28,3]).shape
Out[9]: TensorShape([4, 28, 28, 3])In [10]: tf.reshape(tf.reshape(a,[4,-1]),[4,14,-1,3]).shape
Out[10]: TensorShape([4, 14, 56, 3])In [11]: tf.reshape(tf.reshape(a,[4,-1]),[4,1,-1,3]).shape
Out[11]: TensorShape([4, 1, 784, 3])

**

二 tf.transpose( ) 函数 转置

**
–tf.transpose( )转置函数,默认将所有的轴进行转置,当输入参数perm时,按照perm对应的轴的顺序进行排列
如a. shape = [4,2,5,7]时,若输入参数perm = [3,0,2,1]则当axis=3对应的维度为7,当axis=0对应维度为4,当axis=2对应维度为5,当axis=1对应维度为2,故tf.transpose(a,perm=[3,0,2,1]).shape = [7,4,5,2]

In [12]: a = tf.random.normal([4,3,2,1])                                        In [13]: a.shape
Out[13]: TensorShape([4, 3, 2, 1])In [14]: tf.transpose(a).shape
Out[14]: TensorShape([1, 2, 3, 4])In [16]: tf.transpose(a,perm=[0,1,3,2]).shape#axis=1,shape=4;axis=1,shape=3;axis...: =3,shape=1;axis=2,shape=2
Out[16]: TensorShape([4, 3, 1, 2])
In [3]: a.shape
Out[3]: TensorShape([4, 28, 28, 3])In [4]: tf.transpose(a,[2,0,1,3]).shape
Out[4]: TensorShape([28, 4, 28, 3])In [5]: tf.transpose(a,perm = [0,3,2,1]).shape
Out[5]: TensorShape([4, 3, 28, 28])In [6]: tf.transpose(a,perm = [0,3,1,2]).shape
Out[6]: TensorShape([4, 3, 28, 28])

**

三 tf.expand_dims( ) 函数 维度扩充

**

In [7]: a = tf.random.normal([4,35,8])                                          In [8]: a.shape
Out[8]: TensorShape([4, 35, 8])In [9]: tf.expand_dims(a,axis=0).shape
Out[9]: TensorShape([1, 4, 35, 8])In [10]: tf.expand_dims(a,axis=3).shape
Out[10]: TensorShape([4, 35, 8, 1])
In [11]: a = tf.random.normal([4,35,8])                                         In [12]: a.shape
Out[12]: TensorShape([4, 35, 8])In [13]: tf.expand_dims(a,axis=0).shape
Out[13]: TensorShape([1, 4, 35, 8])In [14]: tf.expand_dims(a,axis=3).shape
Out[14]: TensorShape([4, 35, 8, 1])In [15]: tf.expand_dims(a,axis=-1).shape
Out[15]: TensorShape([4, 35, 8, 1])In [16]: tf.expand_dims(a,axis=-4).shape
Out[16]: TensorShape([1, 4, 35, 8])

**

四 tf.squeeze( )函数 去掉为1的维度

**

In [19]: a = tf.zeros([1,2,1,1,3])                                              In [20]: a.shape
Out[20]: TensorShape([1, 2, 1, 1, 3])In [21]: tf.squeeze(a).shape
Out[21]: TensorShape([2, 3])In [22]: tf.squeeze(a,axis=0).shape
Out[22]: TensorShape([2, 1, 1, 3])In [23]: tf.squeeze(a,axis=2).shape
Out[23]: TensorShape([1, 2, 1, 3])In [24]: tf.squeeze(a,axis=3).shape
Out[24]: TensorShape([1, 2, 1, 3])In [25]: tf.squeeze(a,axis=-2).shape
Out[25]: TensorShape([1, 2, 1, 3])

TensorFlow2.0:维度变换相关推荐

  1. 【TensorFlow2.0】(4) 维度变换、广播

    各位同学好,今天我和大家分享一下TensorFlow2.0中有关数学计算的相关操作,主要内容有: (1) 改变维度:reshape():(2) 维度转置:transpose():(3) 增加维度:ex ...

  2. 深度学习_TensorFlow2.0基础_张量创建,运算,维度变换,采样

    Tensorflow2.0 基础 一:TensorFlow特性 1.TensorFlow An end-to-end open source machine learning platform end ...

  3. mybatis-plus对datetime返回去掉.0_华为AI认证-TensorFlow2.0编程基础

    参考<HCIA-AI2.0培训教材><HCIA-AI2.0实验手册> 认证要求: 了解TensorFlow2.0是什么以及其特点 掌握TensorFlow2.0基础和高阶操作方 ...

  4. 深度学习(8)TensorFlow基础操作四: 维度变换

    深度学习(8)TensorFlow基础操作四: 维度变换 1. View 2. 示例 3. Reshape操作可能会导致潜在的bug 4. tf.transpose 5. Squeeze VS Exp ...

  5. TensorFlow2.0学习

    文章目录 一.TensorFlow的建模流程 1.1 结构化数据建模流程范例 1.1.1 准备数据 1.1.2 定义模型 1.1.3 训练模型 1.1.4 评估模型 1.1.5 使用模型 1.1.6 ...

  6. Tensorflow2.0学习笔记(一)北大曹健老师教学视频1-4讲

    Tensorflow2.0学习笔记(一)北大曹健老师教学视频1-4讲 返回目录 这个笔记现在是主要根据北京大学曹健老师的视频写的,这个视频超级棒,非常推荐. 第一讲 常用函数的使用(包含了很多琐碎的函 ...

  7. 第1章【深度学习简介】--动手学深度学习【Tensorflow2.0版本】

    项目地址:https://github.com/TrickyGo/Dive-into-DL-TensorFlow2.0 UC 伯克利李沐的<动手学深度学习>开源书一经推出便广受好评.很多开 ...

  8. 人工智能实践:Tensorflow2.0笔记 北京大学MOOC(2-1)

    人工智能实践:Tensorflow2.0笔记 北京大学MOOC(2-1) 说明 一.神经网络的优化 1. 神经网络复杂度 2. 学习率策略 2.1 学习率概念回顾 2.2 动态调整学习率 2.2.1 ...

  9. ​TensorFlow2.0系列教程集合版(附PDF下载)

    文章来源于机器学习算法与Python实战,作者奥辰 TensorFlow2.0(1):基本数据结构--张量 TensorFlow2.0(2):数学运算 TensorFlow2.0(3):张量排序.最大 ...

最新文章

  1. 实时车道检测--A Novel Vision-Based Framework for Real-Time Lane Detection and Tracking
  2. 目标检测--RON: Reverse Connection with Objectness Prior Networks for Object Detection
  3. ShaderLab学习小结(十九)RenderToCubemap创建能反射周围环境的效果
  4. 深入理解 Java 线程池:ThreadPoolExecutor
  5. 计算机组成原理(哈工大刘宏伟)135讲(一)
  6. python 在gui中显示logging_如何在GUI中显示print()的输出python
  7. 怎样在Swift中使用NSError
  8. 前端传值后端接收不到_关于前端传参数,后台接收的问题
  9. 隔壁宿舍的都哭了,单片机最小应用系统不懂你都毕不了业
  10. xml python et_python xml处理
  11. ajax传参无法传中文,IE浏览器 ajax传参数值为中文时出现乱码的解决方案
  12. [Python图像处理] 四十三.Python图像形态学处理万字详解(腐蚀膨胀、开闭运算、梯度顶帽黑帽运算)
  13. 【Flink实战系列】Flink 本地 Web UI 的配置及使用
  14. 【JAVA长虹键法】第十式 桥接模式(23种设计模式)
  15. 广东省人力资源和社会保险个人资料下载
  16. 记一次作为主讲人的培训经历
  17. Python统计序列或文件中元素的频度
  18. Java 常用的基本关键字和常用单词
  19. Shell环境变量深入了解
  20. 有什么占内存小又好玩的手游,占内存小的手机游戏

热门文章

  1. Ex 6_23 一个生产系统共包含n个顺序执行的阶段..._第七次作业
  2. Spring笔记02(3种加载配置文件的方式)
  3. 博客园的神回复,程序猿的奇葩神回复[连载][二]
  4. Android学习--写一个发送短信的apk,注意布局文件的处理过程!!!
  5. display:inline-block;在各浏览器下的问题和终极兼容办法
  6. VS2010 + OpenCV2.3配置 ; 在VS2010下安装配置OpenCV2.3 ; 全程截图,绝对能配置好,不能的留言!...
  7. 配置VS2008本地调试.NETFRAMEWORK源代码
  8. 2014025673《嵌入式系统程序设计》第三、四周学习总结
  9. python中反射(__import__和getattr使用)
  10. Note: pdfcrop