[Numpy-discussion] Indexing empty dimensions with empty arrays

Ralf Gommers ralf.gommers at googlemail.com
Mon Dec 26 13:51:37 EST 2011


2011/12/25 Jordi Gutiérrez Hermoso <jordigh at octave.org>

> I have been instructed to bring this issue to the mailing list:
>
>   http://projects.scipy.org/numpy/ticket/1994
>
> The issue is this corner case:

>>> idx = []
>>> x = np.array([])
>>> x[idx]  #works
array([], dtype=float64)
>>> x[:, idx]  #works
array([], dtype=float64)

>>> x = np.ones((5,0))
>>> x[idx]  #works
array([], shape=(0, 0), dtype=float64)
>>> x[:, idx]  #doesn't work
Traceback (most recent call last):
  File "<ipython-input-27-7038691cb565>", line 1, in <module>
    x[:, idx]  #doesn't work
IndexError: invalid index


This is obviously inconsistent, but I think just fixing this one case is
not enough; unexpected behavior with empty inputs/indexes keeps coming up.
Do we need a clear set of rules that all functions follow and tests to
ensure these rules are actually followed, or not?

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111226/4d9a8f47/attachment.html>


More information about the NumPy-Discussion mailing list