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自定义进程池实例分析【生产者、消费者模型问题】
Sep 19 Python
import的本质解析
Oct 30 Python
python中利用h5py模块读取h5文件中的主键方法
Jun 05 Python
实例讲解python中的协程
Oct 08 Python
python看某个模块的版本方法
Oct 16 Python
Python定时任务APScheduler的实例实例详解
Jul 22 Python
Django CSRF跨站请求伪造防护过程解析
Jul 31 Python
Python 使用元类type创建类对象常见应用详解
Oct 17 Python
pygame实现五子棋游戏
Oct 29 Python
使用Python实现分别输出每个数组
Dec 06 Python
通过Python实现一个简单的html页面
May 16 Python
Python3.9新特性详解
Oct 10 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
利用phpexcel把excel导入数据库和数据库导出excel实现
2014/01/09 PHP
PHP配置把错误日志以邮件方式发送方法(Windows系统)
2015/06/23 PHP
让ThinkPHP的模板引擎达到最佳效率的方法详解
2017/03/14 PHP
use jscript Create a SQL Server database
2007/06/16 Javascript
event对象的方法 兼容多浏览器
2009/06/27 Javascript
纯CSS打造的导航菜单(附jquery版)
2010/08/07 Javascript
js控制的遮罩层实例介绍
2013/05/29 Javascript
仿谷歌主页js动画效果实现代码
2013/07/14 Javascript
关于jQuery判断元素是否存在的问题示例探讨
2014/07/21 Javascript
在JS数组特定索引处指定位置插入元素
2014/07/27 Javascript
大型JavaScript应用程序架构设计模式
2016/06/29 Javascript
探索Vue高阶组件的使用
2018/01/08 Javascript
vue2 mint-ui loadmore实现下拉刷新,上拉更多功能
2018/03/21 Javascript
vue keep-alive列表页缓存 详情页返回上一页不刷新,定位到之前位置
2019/11/26 Javascript
[02:01]2018完美盛典-开场舞《双子星》
2018/12/16 DOTA
python基于ID3思想的决策树
2018/01/03 Python
Python实现的rsa加密算法详解
2018/01/24 Python
对python pandas 画移动平均线的方法详解
2018/11/28 Python
PyQt5下拉式复选框QComboCheckBox的实例
2019/06/25 Python
python实现键盘输入的实操方法
2019/07/16 Python
OpenCV3.0+Python3.6实现特定颜色的物体追踪
2019/07/23 Python
结合OpenCV与TensorFlow进行人脸识别的实现
2019/10/10 Python
Python之Numpy的超实用基础详细教程
2019/10/23 Python
如何修复使用 Python ORM 工具 SQLAlchemy 时的常见陷阱
2019/11/19 Python
Python 3 使用Pillow生成漂亮的分形树图片
2019/12/24 Python
基于Python执行dos命令并获取输出的结果
2019/12/30 Python
Python使用Turtle模块绘制国旗的方法示例
2021/02/28 Python
真正的英国宝藏:Mappin & Webb
2019/05/05 全球购物
迟到检讨书1000字
2014/01/15 职场文书
原材料检验岗位职责
2014/03/15 职场文书
英语专业求职信
2014/07/08 职场文书
爱的教育观后感
2015/06/17 职场文书
婚宴父亲致辞
2015/07/27 职场文书
创业计划书之干洗店
2019/09/10 职场文书
Python3的进程和线程你了解吗
2022/03/16 Python
win10壁纸在哪个文件夹 win10桌面背景图片文件位置分享
2022/08/05 数码科技