我有一个包含元组的列表。我需要删除任何包含nan的元组。我该怎么做?
楠的类型是数学。它返回 True。
math.isnan(tmp[1][1][1])
我试过这个,它不起作用:
import math
res = [t for t in tmp if not any(isinstance(n, float) and float('nan') for n in t)]
print(res)
我也试过这个,它不起作用:
nans = {np.nan, math.nan, float('nan')}
[x for x in tmp if not nans.intersection(x)]
下面是一个元组示例
tmp = [[(0, 1.0),
(5, nan),
(10, 1.0),
(15, nan),
(20, 1.0),
(25, nan),
(30, 1.0),
(35, nan),
(40, 0.9808612440191388),
(45, nan),
(50, 0.9719298245614035),
(55, nan),
(60, 0.9712918660287081),
(65, nan),
(70, 0.8947368421052632),
(75, nan),
(80, 0.956140350877193),
(85, nan),
(90, 0.6140350877192983)],
[(0, 0.9635627530364372),
(5, nan),
(10, 1.0),
(15, nan),
(20, 0.9924812030075187),
(25, nan),
(30, 1.0),
(35, nan),
(40, 0.9808612440191388),
(45, nan),
(50, 0.9508771929824561),
(55, nan),
(60, 0.9617224880382775),
(65, nan),
(70, 0.8173374613003096),
(75, nan),
(80, 0.8464912280701754),
(85, nan),
(90, 0.5614035087719298)]]
暮色呼如
相关分类