TensorFlow2.0:张量的合并与分割实例
作者:梅文化_2019 时间:2022-12-02 13:44:49
**
一 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
来源:https://blog.csdn.net/meijie2018_1/article/details/99439186
标签:TensorFlow2.0,张量,合并,分割
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python实现跳一跳自动跳跃功能
2023-04-07 01:57:55
![](https://img.aspxhome.com/file/2023/5/101125_0s.jpg)
Python使用20行代码实现微信聊天机器人
2023-12-04 12:52:06
![](https://img.aspxhome.com/file/2023/8/124638_0s.jpg)
python 按照sheet合并多个Excel的示例代码(多个sheet)
2022-07-13 05:20:20
![](https://img.aspxhome.com/file/2023/9/130619_0s.png)
基于Python实现自动化生成数据报表
2021-11-07 00:42:16
![](https://img.aspxhome.com/file/2023/7/68877_0s.jpg)
利用MySQL主从配置实现读写分离减轻数据库压力
2024-01-18 10:35:07
![](https://img.aspxhome.com/file/2023/9/70389_0s.png)
pyqt5 QListWidget的用法解析
2023-09-24 21:30:31
![](https://img.aspxhome.com/file/2023/9/70749_0s.gif)
SQL Server重温 事务
2012-08-21 10:48:15
完美解决ARIMA模型中plot_acf画不出图的问题
2023-07-13 14:17:34
![](https://img.aspxhome.com/file/2023/1/61761_0s.jpg)
python使用plot绘制未来15天气温折线图
2022-11-06 02:09:41
![](https://img.aspxhome.com/file/2023/0/93620_0s.png)
获取目录下所有文件名的代码
2022-08-20 12:25:14
使用正则表达式匹配tsql注释语句
2024-01-18 16:42:50
浅谈PHP中的Trait使用方法
2023-11-08 09:25:33
![](https://img.aspxhome.com/file/2023/8/55738_0s.png)
Python遍历指定文件及文件夹的方法
2023-04-07 23:10:17
javascript forEach通用循环遍历方法
2024-04-29 13:19:14
Win下PyInstaller 安装和使用教程
2022-08-14 21:29:53
![](https://img.aspxhome.com/file/2023/1/94151_0s.png)
python爬虫爬取网页数据并解析数据
2022-03-03 06:25:02
![](https://img.aspxhome.com/file/2023/8/76808_0s.png)
Vue使用枚举类型实现HTML下拉框步骤详解
2023-07-02 16:45:27
![](https://img.aspxhome.com/file/2023/9/139779_0s.png)
Python中import导入上一级目录模块及循环import问题的解决
2021-09-16 00:53:44
django之状态保持-使用redis存储session的例子
2023-07-29 20:14:07
关于Vue代码可读性的几点建议
2024-05-13 09:08:09