[Numpy-discussion] np.delete fix

Sebastian Berg sebastian@sipsolutions....
Thu Sep 20 20:05:31 CDT 2012


Hey,

I have written a small PR, to fix np.delete, since it would change the
behavior a little (to the better IMO) I think I should also write to the
list? So here is the problem with np.delete:

1. When using slices with negative strides, it does not work (best case)
or give even wrong results.
2. When using an index array, it ignores negative indexes.
3. The fact that it uses setdiff1d makes it unnecessarily slow.

https://github.com/numpy/numpy/pull/452/files fixes these things.

The change is that out of bounds indices would raise an Exception (even
if one might say that they do not matter to deletion), however I
consider that a feature.

And a small example how badly its wrong with slices:
In [1]: arr = np.arange(4)

In [2]: set(arr) - set(arr[1::-1])
Out[2]: set([2, 3])

In [3]: np.delete(arr, np.s_[1::-1])
Out[3]: array([3, 3])

Regards,

Sebastian



More information about the NumPy-Discussion mailing list