I am trying to convert a list that contains numeric values and None values to numpy.array, such that None is replaces with numpy.nan
None
numpy.array
numpy.nan
What about
my_array = np.array(map(lambda x: numpy.nan if x==None else x, my_list))
You simply have to explicitly declare the data type:
>>> my_list = [3, 5, 6, None, 6, None] >>> np.array(my_list, dtype=np.float) array([ 3., 5., 6., nan, 6., nan])