Skip to content

Inconsistent indexing of arrays with no elements, depending on shape (Trac #1171) #1769

@thouis

Description

@thouis

Original ticket http://projects.scipy.org/numpy/ticket/1171 on 2009-07-14 by trac user jguyer, assigned to unknown.

An empty, rank-0 array can be indexed with an empty list:

#!python
>>> import numpy as np
>>> np.__version__
'1.3.0.dev6304'
>>> a = np.zeros((0,))
>>> a[..., []]
array([], dtype=float64)

but an empty array of higher rank throws an index error

#!python
>>> b = np.zeros((1, 0))
>>> b[..., []]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: invalid index

We have a not-completely-insane reason for wanting the second case to return array([], shape=(1, 0), dtype=float64). At a minimum, it seems the two cases should be consistent.

I wonder if this is related to ticket:1169?

I see this on a 10.5.7 Mac, with Python 2.6.2 and NumPy 1.3.0dev and on a Debian etch machine running Python 2.4.4 and NumPy 1.2.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions