Error in deleting an empty row with numpy.delete (Trac #2140) #600

Closed
numpy-gitbot opened this Issue Oct 19, 2012 · 1 comment

2 participants

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/2140 on 2012-05-22 by trac user jansb, assigned to unknown.

Hello,

I get an error when I try to delete nothing from an array with a shape of one axis equal zero.

What works:

In [1]: z=np.zeros((0,))

In [2]: z, z.shape
Out[2]: (array([], dtype=float64), (0,))

In [3]: numpy.delete(z,[],0)
Out[3]: array([], dtype=float64)

What gives an index error:

In [4]: z=np.zeros((0,2))

In [5]: z, z.shape
Out[5]: (array([], shape=(0, 2), dtype=float64), (0, 2))

In [6]: numpy.delete(z,[],0)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/home/jansb/.local/share/Trash/files/estimbuilder 3/tests/<ipython-input-6-f9a27bc2cbeb> in <module>()
----> 1 numpy.delete(z,[],0)

/usr/lib/python2.7/dist-packages/numpy/lib/function_base.pyc in delete(arr, obj, axis)
   3383         obj = setdiff1d(all, obj)
   3384         slobj[axis] = obj
-> 3385         new = arr[slobj]
   3386     if wrap:
   3387         return wrap(new)

IndexError: invalid index

What works:

In [8]: z=np.zeros((0,2))

In [9]: z, z.shape
Out[9]: (array([], shape=(0, 2), dtype=float64), (0, 2))

In [10]: numpy.delete(z,[],1)
Out[10]: array([], shape=(0, 2), dtype=float64)

Is this a bug or wanted behaviour?

Best regards,
jansb

@seberg
NumPy member

This is fixed with gh-2701.

@seberg seberg closed this May 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment