当前位置: 移动技术网 > IT编程>脚本编程>Python > TensorFlow2.0:张量的合并与分割实例

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

2020年03月09日  | 移动技术网IT编程  | 我要评论

傲世九重天墨坛,音乐教师工作计划,湖南二本

**

一 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:张量的合并与分割实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网