03-numpy-笔记-expand_dims

>>> x = np.array([[1,2,3],[4,5,6]])
>>> x.shape
(2, 3)
>>> np.expand_dims(x, 0)
array([[[1, 2, 3],
        [4, 5, 6]]])
>>> np.expand_dims(x, 1)
array([[[1, 2, 3]],

       [[4, 5, 6]]])
>>> np.expand_dims(x, 2)
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])
>>> np.expand_dims(x, 3)
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])
>>> np.expand_dims(x, 4)
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])
>>> np.expand_dims(x, 1).shape
(2, 1, 3)
>>> np.expand_dims(x, 2).shape
(2, 3, 1)
>>> np.expand_dims(x, 3).shape
(2, 3, 1)
>>> np.expand_dims(x, 4).shape
(2, 3, 1)
>>> np.expand_dims(x, 0).shape
(1, 2, 3)

1. 分3部分来看。

2. expand_dims直观来说就是将某一维度展成1维,看shape的形式便可知。

3. 哪一维要设置成1,就将原始DATA重新组合,细心看输出的数据的重排形式。

4. 维度从0开始,超过都表示最后一维,-1也是最后一维。

 

posted @ 2018-04-15 21:15  路边的十元钱硬币  阅读(407)  评论(0编辑  收藏  举报