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

thouis opened this Issue Oct 19, 2012 · 3 comments


None yet
3 participants

thouis commented Oct 19, 2012

Original ticket on 2009-07-14 by trac user jguyer, assigned to unknown.

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

>>> import numpy as np
>>> np.__version__
>>> a = np.zeros((0,))
>>> a[..., []]
array([], dtype=float64)

but an empty array of higher rank throws an index error

>>> 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.


thouis commented Oct 19, 2012

@teoliphant wrote on 2009-07-15

I agree with this reasoning. Does someone have a patch?


thouis commented Oct 19, 2012

Milestone changed to Unscheduled by @cournape on 2009-11-25


nouiz commented May 15, 2013

Fix issue have been fixed by gh-2701 from its description. Can someone close it?

seberg closed this May 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment