TensorFlow2.0:张量的合并与分割实例


Posted in Python onJanuary 19, 2020

**

一 tf.concat( ) 函数?合并
**

In [2]: a = tf.ones([4,35,8])                          

In [3]: b = tf.ones([2,35,8])                          

In [4]: c = tf.concat([a,b],axis=0)                       

In [5]: c.shape                                 
Out[5]: TensorShape([6, 35, 8])

In [6]: a = tf.ones([4,32,8])                          

In [7]: b = tf.ones([4,3,8])                          

In [8]: c = tf.concat([a,b],axis=1)                       

In [9]: c.shape                                 
Out[9]: TensorShape([4, 35, 8])

**

二 tf.stack( ) 函数?数据的堆叠,创建新的维度
**

In [2]: a = tf.ones([4,35,8])                          

In [3]: a.shape                                 
Out[3]: TensorShape([4, 35, 8])

In [4]: b = tf.ones([4,35,8])                          

In [5]: b.shape                                 
Out[5]: TensorShape([4, 35, 8])

In [6]: tf.concat([a,b],axis=-1).shape                     
Out[6]: TensorShape([4, 35, 16])

In [7]: tf.stack([a,b],axis=0).shape                      
Out[7]: TensorShape([2, 4, 35, 8])

In [8]: tf.stack([a,b],axis=3).shape                      
Out[8]: TensorShape([4, 35, 8, 2])

**

三 tf.unstack( )函数?解堆叠
**

In [16]: a = tf.ones([4,35,8])                                                                                       

In [17]: b = tf.ones([4,35,8])                                                                                       

In [18]: c = tf.stack([a,b],axis=0)                                                                                     

In [19]: a.shape,b.shape,c.shape                                                                                      
Out[19]: (TensorShape([4, 35, 8]), TensorShape([4, 35, 8]), TensorShape([2, 4, 35, 8]))

In [20]: aa,bb = tf.unstack(c,axis=0)                                                                                    

In [21]: aa.shape,bb.shape                                                                                         
Out[21]: (TensorShape([4, 35, 8]), TensorShape([4, 35, 8]))

In [22]: res = tf.unstack(c,axis=1)                                                                                     

In [23]: len(res)                                                                                              
Out[23]: 4

**

四 tf.split( ) 函数
**

In [16]: a = tf.ones([4,35,8])                                                                                       

In [17]: b = tf.ones([4,35,8])                                                                                       

In [18]: c = tf.stack([a,b],axis=0)                                                                                     

In [19]: a.shape,b.shape,c.shape                                                                                      
Out[19]: (TensorShape([4, 35, 8]), TensorShape([4, 35, 8]), TensorShape([2, 4, 35, 8]))

In [20]: aa,bb = tf.unstack(c,axis=0)                                                                                    

In [21]: aa.shape,bb.shape                                                                                         
Out[21]: (TensorShape([4, 35, 8]), TensorShape([4, 35, 8]))

In [22]: res = tf.unstack(c,axis=1)                                                                                     

In [23]: len(res)                                                                                              
Out[23]: 4

以上这篇TensorFlow2.0:张量的合并与分割实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python创建和使用字典实例详解
Nov 01 Python
python的三目运算符和not in运算符使用示例
Mar 03 Python
利用Pandas读取文件路径或文件名称包含中文的csv文件方法
Jul 04 Python
对Python模块导入时全局变量__all__的作用详解
Jan 11 Python
Python中的Socket 与 ScoketServer 通信及遇到问题解决方法
Apr 01 Python
python增加图像对比度的方法
Jul 12 Python
python3 反射的四种基本方法解析
Aug 26 Python
python GUI库图形界面开发之PyQt5 MDI(多文档窗口)QMidArea详细使用方法与实例
Mar 05 Python
PyCharm+Pipenv虚拟环境开发和依赖管理的教程详解
Apr 16 Python
Keras自定义IOU方式
Jun 10 Python
python中id函数运行方式
Jul 03 Python
Python+OpenCV实现在图像上绘制矩形
Mar 21 Python
tensorflow中tf.slice和tf.gather切片函数的使用
Jan 19 #Python
tensorflow实现对张量数据的切片操作方式
Jan 19 #Python
python系统指定文件的查找只输出目录下所有文件及文件夹
Jan 19 #Python
Python插入Elasticsearch操作方法解析
Jan 19 #Python
Docker部署Python爬虫项目的方法步骤
Jan 19 #Python
Python Selenium参数配置方法解析
Jan 19 #Python
浅谈tensorflow中张量的提取值和赋值
Jan 19 #Python
You might like
PHP中的超全局变量
2006/10/09 PHP
测试php函数的方法
2013/11/13 PHP
Yii模型操作之criteria查找数据库的方法
2016/07/15 PHP
PHP mysqli_free_result()与mysqli_fetch_array()函数详解
2016/09/21 PHP
ThinkPHP发送邮件示例代码
2016/10/08 PHP
浅谈PHP中try{}catch{}的使用方法
2016/12/09 PHP
javascript+mapbar实现地图定位
2010/04/09 Javascript
Js组件的一些写法
2010/09/10 Javascript
Jquery中删除元素的实现代码
2011/12/29 Javascript
JavaScript 验证码的实例代码(附效果图)
2013/03/22 Javascript
js数组转json并在后台对其解析具体实现
2013/11/20 Javascript
点击button获取text内容并改变样式的js实现
2014/09/09 Javascript
举例讲解Node.js中的Writable对象
2015/07/29 Javascript
详解ES6中的let命令
2020/04/05 Javascript
Zepto实现密码的隐藏/显示
2017/04/07 Javascript
详解微信小程序Radio选中样式切换
2017/07/06 Javascript
前端把html表格生成为excel表格的实例
2017/09/19 Javascript
AngularJS实现表单元素值绑定操作示例
2017/10/11 Javascript
在vue项目中使用sass语法问题
2019/07/18 Javascript
优化Vue中date format的性能详解
2020/01/13 Javascript
VUE实现自身整体组件销毁的示例代码
2020/01/13 Javascript
[13:18]《一刀刀一天》之DOTA全时刻21:详解TI新赛制 A队再露獠牙
2014/06/24 DOTA
用Python实现斐波那契(Fibonacci)函数
2016/03/25 Python
wxPython实现窗口用图片做背景
2018/04/25 Python
python的sorted用法详解
2019/06/25 Python
对python中的*args与**kwgs的含义与作用详解
2019/08/28 Python
使用Python的Turtle库绘制森林的实例
2019/12/18 Python
详解Css3新特性应用之过渡与动画
2017/01/10 HTML / CSS
英国领先的游戏零售商:GAME
2019/09/24 全球购物
校庆活动方案
2014/03/31 职场文书
需求分析说明书
2014/05/09 职场文书
酒店仓管员岗位职责
2015/04/01 职场文书
2015年教研工作总结
2015/05/23 职场文书
《失物招领》教学反思
2016/02/20 职场文书
初中政治教师教学反思
2016/02/23 职场文书
springboot如何接收application/x-www-form-urlencoded类型的请求
2021/11/02 Java/Android