In my code, I must go from a large nested list (python list of python lists) and in each sublist, some entries may be the numpy values NaN. When I create this nested list it looks something like this:
import numpy as np
nested_list = [[np.nan, 19], ['a', np.nan]]
>>> print(nested_list)
[[nan, 19], ['a', nan]]
I expect when I evaluate the equality of a NaN element of the sublist against itself, I should get False due to it being a null value which I do:
>>>print(nested_list[1][1] == nested_list[1][1])
False
Now, I want to turn this nested list into a 2d numpy array, but when I do, the NaN values just turn into strings and do not retain their null-ness:
arr = np.array(list_of_lists)
>>>print(arr)
[['nan' '19']
['a' 'nan']]
>>>print(arr[1][1] == arr[1][1])
True
How do I keep NaN from being turned into a string?