Can someone provide me with a better (simpler, more readable, more Pythonic, more efficient, etc.) way to remove multiple values from an array than the following:
import numpy as np
A good answer to this question will give the same result as the above code (i.e. new_array ), but it can better deal with equality between floats than the code does.
Bonus
Can someone explain to me why this leads to the wrong result?
In [5]: np.delete(x, x == a) /usr/lib/python2.7/dist-packages/numpy/lib/function_base.py:3254: FutureWarning: in the future insert will treat boolean arrays and array-likes as boolean index instead of casting it to integer "of casting it to integer", FutureWarning) Out[5]: array([ 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., 130., 140., 150., 160., 170., 180., 190., 200., 210., 220., 230., 240., 250., 260., 270., 280., 290., 300., 310., 320., 330., 340., 350., 360.])
The values 0 and 10 have been deleted, not just 0 ( a ).
Note. x == a meets expectations (so the problem is inside np.delete ):
In [6]: x == a Out[6]: array([ True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False], dtype=bool)
Note also that np.delete(x, np.where(x == a)) gives the correct result. Thus, it seems to me that np.delete cannot handle boolean indexes.