Skip to content

Indexing with single boolean behaves inconsistently #6104

@sinhrks

Description

@sinhrks

Related to #4353, #4980, but would like to ask the cases when the indexer is a single bool.

  1. In normal array, bool looks coerces to int. Is this intended, or should be regarded as a boolean indexing with different shape (DEP: Deprecate boolean array indices with non-matching shape #4353)?

    np.__version__
    # '1.9.2'
    
    np.array([0])[True]
    # IndexError: index 1 is out of bounds for axis 0 with size 1
    np.array([0])[False]
    #0
    
  2. 0-dim array behaves quite strangely. I understand this should raise IndexError if it coerces to int.

    np.array(0)[False]
    # array([], dtype=int64)
    np.array(0)[True]
    # array([0])
    
    np.array(0)[0]
    # IndexError: too many indices for array
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions