To remove NaN values from a NumPy array x:
x = x[~numpy.isnan(x)]
Explanation
The inner function numpy.isnan returns a boolean/logical array which has the value True everywhere that x is not-a-number. Since we want the opposite, we use the logical-not operator ~ to get an array with Trues everywhere that x is a valid number.
Lastly, we use this logical array to index into the original array x, in order to retrieve just the non-NaN values.
To remove NaN values from a NumPy array x:
x = x[~numpy.isnan(x)]
Explanation
The inner function numpy.isnan returns a boolean/logical array which has the value True everywhere that x is not-a-number. Since we want the opposite, we use the logical-not operator ~ to get an array with Trues everywhere that x is a valid number.
Lastly, we use this logical array to index into the original array x, in order to retrieve just the non-NaN values.
filter(lambda v: v==v, x)
works both for lists and numpy array since v!=v only for NaN
This is probably because the np.isnan() is failing to deal with string types among your possible element types in collection. You could try to use panda's isnull() to remove NaN values.
import pandas as pa
import numpy as np
a = ['A', np.nan, np.nan, 1.67, 8]
a = [x for x in a if not pa.isnull(x)]
print(a)
There's function in pandas called pandas.DataFrame.dropna which drops all the columns with nan values. Just create DataFrame if you didn't, and do df.dropna().