numpy array indexing: list index and np.array index give different result

后端 未结 2 1616
粉色の甜心
粉色の甜心 2021-01-14 16:53

I am trying to index an np.array using list and np.array indexes. But they give different result.

Here is an illustration:

import numpy         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-14 17:09

    From numpy indexing documentation:

    ndarrays can be indexed using the standard Python x[obj] syntax, where x is the array and obj the selection.

    ...
    Basic slicing occurs when obj is a slice object (constructed by start:stop:step notation inside of brackets), an integer, or a tuple of slice objects and integers. Ellipsis and newaxis objects can be interspersed with these as well. In order to remain backward compatible with a common usage in Numeric, basic slicing is also initiated if the selection object is any non-ndarray sequence (such as a list) containing slice objects, the Ellipsis object, or the newaxis object, but not for integer arrays or other embedded sequences. ...

提交回复
热议问题