[SciPy-User] [scipy-user] How to remove a value from an np array?

David Warde-Farley wardefar@iro.umontreal...
Fri Jan 27 12:20:48 CST 2012


On Fri, Jan 27, 2012 at 06:48:45PM +0100, Fabien Lafont wrote:
> And how can I remove a specific element designated by its position
> numer? like remove(a[8]) for exemple.

This is generally not something you want to be doing with NumPy arrays. NumPy
arrays represent fixed blocks of memory, removing an element means
reallocating the array and copying values before and after position 8 is the
only way.

If a is one-dimensional, then np.concatenate(a[:8], a[9:]) will do the job,
but if you are going to be frequently performing this kind of operation you
will get better performance out of a plain Python list.

David


More information about the SciPy-User mailing list