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和Ruby中each循环引用变量问题(一个隐秘BUG?)
Jun 04 Python
在Python中操作文件之seek()方法的使用教程
May 24 Python
python版学生管理系统
Jan 10 Python
Python3生成手写体数字方法
Jan 30 Python
Python中pip更新和三方插件安装说明
Jul 08 Python
Python 实现某个功能每隔一段时间被执行一次的功能方法
Oct 14 Python
Python matplotlib通过plt.scatter画空心圆标记出特定的点方法
Dec 13 Python
Python基本数据结构与用法详解【列表、元组、集合、字典】
Mar 23 Python
Django框架静态文件使用/中间件/禁用ip功能实例详解
Jul 22 Python
关于numpy中eye和identity的区别详解
Nov 29 Python
Python线程协作threading.Condition实现过程解析
Mar 12 Python
在Anaconda3下使用清华镜像源安装TensorFlow(CPU版)
Apr 19 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开发规范手册之PHP代码规范详解
2011/01/13 PHP
PHP sprintf()函数用例解析
2011/05/18 PHP
解析PHP的session过期设置
2013/06/29 PHP
Drupal7连接多个数据库及常见问题解决
2014/03/02 PHP
destoon二次开发模板及调用语法汇总
2014/06/21 PHP
PHP处理Json字符串解码返回NULL的解决方法
2014/09/01 PHP
laravel 5 实现模板主题功能(续)
2015/03/02 PHP
详解YII关联查询
2016/01/10 PHP
php parse_str() 函数的定义和用法
2016/05/23 PHP
微信开发之获取JSAPI TICKET
2017/07/07 PHP
超级兔子让浮动层消失的前因后果
2007/03/09 Javascript
(JS实现)MapBar中坐标的加密和解密的脚本
2007/05/16 Javascript
jQuery的deferred对象使用详解
2011/08/20 Javascript
file模式访问网页时iframe高度自适应解决方案
2013/01/16 Javascript
jQuery实现长按按钮触发事件的方法
2015/02/02 Javascript
基于jQuery和CSS3制作响应式水平时间轴附源码下载
2015/12/20 Javascript
seajs学习之模块的依赖加载及模块API的导出
2016/10/20 Javascript
浅谈对于react-thunk中间件的简单理解
2019/05/01 Javascript
JS前后端实现身份证号验证代码解析
2020/07/23 Javascript
Python计时相关操作详解【time,datetime】
2017/05/26 Python
Python 实现简单的shell sed替换功能(实例讲解)
2017/09/29 Python
Python学习笔记之if语句的使用示例
2017/10/23 Python
Python基于辗转相除法求解最大公约数的方法示例
2018/04/04 Python
浅谈pycharm的xmx和xms设置方法
2018/12/03 Python
python 实现控制鼠标键盘
2020/11/27 Python
详解Sticky Footer 绝对底部的两种套路
2017/11/03 HTML / CSS
用HTML5.0制作网页的教程
2010/05/30 HTML / CSS
Christys’ Hats官网:英国帽子制造商
2018/11/28 全球购物
Chi Chi London官网:购买连衣裙和礼服
2020/10/25 全球购物
大学毕业生通用求职信
2013/09/28 职场文书
护士实习生自我鉴定范文
2013/12/10 职场文书
运动会通讯稿400字
2014/01/28 职场文书
中文专业毕业生自荐信
2014/05/24 职场文书
2016应届毕业生就业指导课心得体会
2016/01/15 职场文书
MySQL 数据库 增删查改、克隆、外键 等操作
2022/05/11 MySQL
vue中data里面的数据相互使用方式
2022/06/05 Vue.js