我有两个数组,一个是x,一个是y。这两个数组之间没有关系,但我想能够在线性插值点之间进行插值,使得y=f(x),以便我可以计算出在y = 0.95时的x值。到目前为止,我所使用的方法如下:
import numpy as np
from scipy.interpolate import interp1d
def NearestValue(array,value):
#returns the index of the element of the array which is closest to value
idx = (np.abs(array-value)).argmin()
return idx
x =[[ 0. ],[ 9.9],[ 19.8],[ 31.5],[ 41.9],[ 49.1],[ 59. ],[ 70. ],[ 80.4],[ 100. ]]
y= [ 0.011905, 0.140795, 0.600562, 0.757247, 0.874564, 0.934559, 0.961719, 0.986099, 0.990284, 0.998254]
f = interp1d(x,y)
x_new = np.linspacex(x[0],x[9],1000)
y_new = f(x_new)
NearestIndex = NearestValue(y_new,0.95)
x_nearest = x_new[NearestIndex]
这个方法会返回x_new中与0.95最接近的y_new值所对应的数值。是否有办法计算出y值恰好为0.95时对应的x值?