问题
import numpy as np
print max([np.nan, 1, 2, 3, 4])
print max([1, 2, 3, 4, np.nan])
print max([1, 2, 3, np.nan, 4])
the first will print nan as list's max value
the second will print 4 as list's max value
the third will print 4 as list's max value
Is there a solution for this problem? Make all math function just ignore nan?
回答1:
Use np.nanmax() to ignore any NaNs:
In [57]: np.nanmax([np.nan, 1, 2, 3, 4])
Out[57]: 4.0
来源:https://stackoverflow.com/questions/43042424/find-max-value-of-a-list-with-numpy-nan