我有一个清单。我想找到最接近给定数字的值。一切正常。但问题是,它产生nan两个唯一数字的输出。在这里我提供我的完整数据
我的代码和输出:
#### Find the index of nearest value in a array
def find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return array[idx] #for returing nearest value
r = [0.209272 , 0.172816 , 0.1297975 , 0.0777895 , 0.008605 ,
np.nan, np.nan, np.nan, np.nan, np.nan]
rc = 0.38420566666666667
rse_ed = find_nearest(r,0.01) ### close to 0.01 is 0.008605
rse_st = find_nearest(r,rc*0.4) #### close to 0.15368226666666668 is 0.172816
print(rse_st,rse_ed)
nan,nan ###
预期输出:
print(rse_st,rse_ed)
0.172816,0.008605
波斯汪
相关分类