最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

TensorFlow的reshape操作 tf.reshape的實(shí)現(xiàn)

 更新時(shí)間:2020年04月19日 10:18:48   作者:Ai_踐行者  
這篇文章主要介紹了TensorFlow的reshape操作 tf.reshape的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

初學(xué)tensorflow,如果寫的不對(duì)的,請(qǐng)更正,謝謝!

tf.reshape(tensor, shape, name=None)

函數(shù)的作用是將tensor變換為參數(shù)shape的形式。

其中shape為一個(gè)列表形式,特殊的一點(diǎn)是列表中可以存在-1。-1代表的含義是不用我們自己指定這一維的大小,函數(shù)會(huì)自動(dòng)計(jì)算,但列表中只能存在一個(gè)-1。(當(dāng)然如果存在多個(gè)-1,就是一個(gè)存在多解的方程了)

好了我想說的重點(diǎn)還有一個(gè)就是根據(jù)shape如何變換矩陣。其實(shí)簡單的想就是,

reshape(t, shape) => reshape(t, [-1]) => reshape(t, shape)

首先將矩陣t變?yōu)橐痪S矩陣,然后再對(duì)矩陣的形式更改就可以了。

官方的例子:

# tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]
# tensor 't' has shape [9]
reshape(t, [3, 3]) ==> [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]

# tensor 't' is [[[1, 1], [2, 2]],
#        [[3, 3], [4, 4]]]
# tensor 't' has shape [2, 2, 2]
reshape(t, [2, 4]) ==> [[1, 1, 2, 2],
            [3, 3, 4, 4]]

# tensor 't' is [[[1, 1, 1],
#         [2, 2, 2]],
#        [[3, 3, 3],
#         [4, 4, 4]],
#        [[5, 5, 5],
#         [6, 6, 6]]]
# tensor 't' has shape [3, 2, 3]
# pass '[-1]' to flatten 't'
reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]

# -1 can also be used to infer the shape

# -1 is inferred to be 9:
reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
             [4, 4, 4, 5, 5, 5, 6, 6, 6]]
# -1 is inferred to be 2:
reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
             [4, 4, 4, 5, 5, 5, 6, 6, 6]]
# -1 is inferred to be 3:
reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1],
               [2, 2, 2],
               [3, 3, 3]],
               [[4, 4, 4],
               [5, 5, 5],
               [6, 6, 6]]]

# tensor 't' is [7]
# shape `[]` reshapes to a scalar
reshape(t, []) ==> 7

在舉幾個(gè)例子或許就清楚了,有一個(gè)數(shù)組z,它的shape屬性是(4, 4)

z = np.array([[1, 2, 3, 4],
     [5, 6, 7, 8],
     [9, 10, 11, 12],
     [13, 14, 15, 16]])
z.shape
(4, 4)

z.reshape(-1)

z.reshape(-1)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])

z.reshape(-1, 1)
也就是說,先前我們不知道z的shape屬性是多少,但是想讓z變成只有一列,行數(shù)不知道多少,通過`z.reshape(-1,1)`,Numpy自動(dòng)計(jì)算出有12行,新的數(shù)組shape屬性為(16, 1),與原來的(4, 4)配套。

z.reshape(-1,1)
 array([[ 1],
    [ 2],
    [ 3],
    [ 4],
    [ 5],
    [ 6],
    [ 7],
    [ 8],
    [ 9],
    [10],
    [11],
    [12],
    [13],
    [14],
    [15],
    [16]])

z.reshape(-1, 2)

newshape等于-1,列數(shù)等于2,行數(shù)未知,reshape后的shape等于(8, 2)

 z.reshape(-1, 2)
 array([[ 1, 2],
    [ 3, 4],
    [ 5, 6],
    [ 7, 8],
    [ 9, 10],
    [11, 12],
    [13, 14],
    [15, 16]])

到此這篇關(guān)于TensorFlow的reshape操作 tf.reshape的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)TensorFlow的reshape操作 tf.reshape內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

九寨沟县| 沙田区| 罗源县| 阿勒泰市| 安多县| 郓城县| 大方县| 南岸区| 区。| 林西县| 乌拉特后旗| 工布江达县| 萝北县| 大城县| 高邮市| 玉门市| 黄龙县| 石景山区| 塔城市| 巩留县| 仙桃市| 加查县| 南漳县| 长乐市| 敦煌市| 汪清县| 巧家县| 阿鲁科尔沁旗| 石楼县| 韶山市| 建湖县| 淳化县| 湟源县| 星座| 南通市| 桐梓县| 鲜城| 婺源县| 威远县| 教育| 洮南市|