TensorFlow2.0:張量的合并與分割實(shí)例
**
一 tf.concat( ) 函數(shù)–合并
**
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( ) 函數(shù)–數(shù)據(jù)的堆疊,創(chuàng)建新的維度
**
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( )函數(shù)–解堆疊
**
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( ) 函數(shù)
**
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:張量的合并與分割實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
django多種支付、并發(fā)訂單處理實(shí)例代碼
在本篇文章里小編給大家整理的是關(guān)于django多種支付、并發(fā)訂單處理實(shí)例代碼,需要的朋友們可以學(xué)習(xí)下。2019-12-12Python 實(shí)現(xiàn)微信自動(dòng)回復(fù)的方法
這篇文章主要介紹了Python 實(shí)現(xiàn)微信自動(dòng)回復(fù)的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-09-09Python?queue雙端隊(duì)列模塊及用法小結(jié)
雙端隊(duì)列是一種具有隊(duì)列和棧性質(zhì)的線性數(shù)據(jù)結(jié)構(gòu),本文主要介紹了Python?queue雙端隊(duì)列模塊及用法小結(jié),文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-02-02對(duì)YOLOv3模型調(diào)用時(shí)候的python接口詳解
今天小編就為大家分享一篇對(duì)YOLOv3模型調(diào)用時(shí)候的python接口詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-08-08Jupyter Notebook切換虛擬環(huán)境的三種方法
本文主要介紹了Jupyter Notebook切換虛擬環(huán)境的三種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07