"""
nan 三种生成方法,判断方法,来源
"""
#Gen nan
xf = float('nan')
import numpy as np
xn = np.nan
from decimal import Decimal
xd = Decimal('nan')
# souce of nan, 'inf' -'inf', inf/inf
x1 = float('inf') + 2*float('inf')
x2 = float('inf') - float('inf')
x3 = float('inf') / float('inf')
# judge nan
print(xf != xf)
print(xn != xn)
print(xd != xd)
# nanmean, nanmax, nanmin, nanstd
ls = [2,3,4, xf]
print('mean = ', np.mean(ls))
print('nanmean = ', np.nanmean(ls))
print('nanmax = ', np.nanmax(ls))
print('nanmin = ', np.nanmin(ls))
print('nanstd = ', np.nanstd(ls))
ls.extend([str(xf), str(xd)])
python的nan生成、表示、判决和忽略nan的统计运算
最新推荐文章于 2024-09-11 05:59:04 发布