【发布时间】:2023-02-18 00:07:26
【问题描述】:
我不能使用 numpy,如何模拟 .nansum 方法?例子
x = [1, NaN, 2, 10]
【问题讨论】:
我不能使用 numpy,如何模拟 .nansum 方法?例子
x = [1, NaN, 2, 10]
【问题讨论】:
您可以将生成器表达式传递给sum。
from math import isnan
print(sum(e for e in x if not isnan(e)))
【讨论】: