本文介绍了用numpy nan查找列表的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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])
第一个将nan打印为列表的最大值
the first will print nan as list's max value
第二个将打印4作为列表的最大值
the second will print 4 as list's max value
第三个将打印4作为列表的最大值
the third will print 4 as list's max value
是否有解决此问题的方法?让所有数学函数都忽略nan吗?
Is there a solution for this problem? Make all math function just ignore nan?
推荐答案
使用 np.nanmax()
忽略任何NaN:
Use np.nanmax()
to ignore any NaNs:
In [57]: np.nanmax([np.nan, 1, 2, 3, 4])
Out[57]: 4.0
这篇关于用numpy nan查找列表的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!