小编cko*_*g80的帖子

Python numpy;冒号和省略号索引之间的区别

我一直在尝试使用冒号和省略号进行 Numpy 数组索引。但是,我无法理解我得到的结果。

下面是示例代码:

>>> a = np.array([[1,2],[3,4]])
>>> a
array([[1, 2],
       [3, 4]])

>>> a[:,np.newaxis]     #  <-- the shape of the rows are unchanged
array([[[1, 2]],

       [[3, 4]]])
>>> a[...,np.newaxis]   #  <-- the shape of the rows changed from horizontal to vertical
array([[[1],
        [2]],

       [[3],
        [4]]])
Run Code Online (Sandbox Code Playgroud)

python indexing numpy ellipsis

3
推荐指数
1
解决办法
1192
查看次数

标签 统计

ellipsis ×1

indexing ×1

numpy ×1

python ×1