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面向对象编程中关于类和方法的学习笔记
Jun 30 Python
Python实现批量读取图片并存入mongodb数据库的方法示例
Apr 02 Python
Django实现全文检索的方法(支持中文)
May 14 Python
举例讲解Python常用模块
Mar 08 Python
Python实现微信消息防撤回功能的实例代码
Apr 29 Python
python 字典操作提取key,value的方法
Jun 26 Python
Python字符串处理的8招秘籍(小结)
Aug 13 Python
关于python导入模块import与常见的模块详解
Aug 28 Python
python中几种自动微分库解析
Aug 29 Python
150行python代码实现贪吃蛇游戏
Apr 24 Python
基于PyTorch的permute和reshape/view的区别介绍
Jun 18 Python
python实现AdaBoost算法的示例
Oct 03 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.ini中的php-5.2.0配置指令详解
2008/03/27 PHP
php实现mysql事务处理的方法
2014/12/25 PHP
JS 实现Table相同行的单元格自动合并示例代码
2013/08/27 Javascript
JS动态添加与删除select中的Option对象(示例代码)
2013/12/20 Javascript
多选列表框动态添加,移动,删除,全选等操作的简单实例
2014/01/13 Javascript
jquery scroll()区分横向纵向滚动条的方法
2014/04/04 Javascript
Jquery实现由下向上展开效果的例子
2014/12/08 Javascript
Nodejs为什么选择javascript为载体语言
2015/01/13 NodeJs
JS获取iframe中longdesc属性的方法
2015/04/01 Javascript
jQuery版本升级踩坑大全
2016/01/12 Javascript
全面解析Bootstrap中tab(选项卡)的使用方法
2016/06/06 Javascript
JS常用算法实现代码
2016/11/14 Javascript
Vue 固定头 固定列 点击表头可排序的表格组件
2016/11/25 Javascript
一次围绕setTimeout的前端面试经验分享
2017/06/15 Javascript
基于jQuery实现的单行公告活动轮播效果
2017/08/23 jQuery
JavaScript键盘事件常见用法实例分析
2019/01/03 Javascript
js实现星星打分效果
2020/07/05 Javascript
[02:36]DOTA2上海特锦赛 回忆电竞生涯的重要瞬间
2016/03/25 DOTA
Flask SQLAlchemy一对一,一对多的使用方法实践
2013/02/10 Python
python字典get()方法用法分析
2015/04/17 Python
Python常用算法学习基础教程
2017/04/13 Python
用python写个自动SSH登录远程服务器的小工具(实例)
2017/06/17 Python
深入分析python数据挖掘 Json结构分析
2018/04/21 Python
查看TensorFlow checkpoint文件中的变量名和对应值方法
2018/06/14 Python
详解Django+Uwsgi+Nginx的生产环境部署
2018/06/25 Python
Python 面试中 8 个必考问题
2018/11/16 Python
Python中关于浮点数的冷知识
2019/09/22 Python
Python批量启动多线程代码实例
2020/02/18 Python
Snapfish爱尔兰:在线照片打印和个性化照片礼品
2018/09/17 全球购物
建筑文秘专业个人求职信范文
2013/12/28 职场文书
运动会领导邀请函
2014/01/10 职场文书
2014年骨干教师工作总结
2014/12/19 职场文书
物业前台接待岗位职责
2015/04/03 职场文书
Python编写可视化界面的全过程(Python+PyCharm+PyQt)
2021/05/17 Python
详解Vue slot插槽
2021/11/20 Vue.js
js面向对象编程OOP及函数式编程FP区别
2022/07/07 Javascript