cko*_*g80 3 python indexing numpy ellipsis
我一直在尝试使用冒号和省略号进行 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)