使用两个数组的线性插入

Cha*_*She 0 python numpy

我有以下数组:

List_CD = [2410.412434205376, 2287.6750893063017, 2199.2602314650626, 2124.4647889960825, 2084.5846633116403, 2031.9053600816167, 1996.2844020790524, 1957.1098650203032, 1938.4110044030583, 1900.0783178367647, 1877.6396548046785, 1868.2902104714337, 1844.9165996383219, 1816.8682911816766]
List_Dose = [10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 34.0, 36.0]
Run Code Online (Sandbox Code Playgroud)

我想要做的是使用以下方法进行简单的插值:

dsize = numpy.interp(2000., List_CD, List_Dose)
Run Code Online (Sandbox Code Playgroud)

期望的结果是在20.0和22.0之间,但我一直得到10.0的值

有人可以帮忙吗?

eum*_*iro 7

xp : 1-D sequence of floats
    The x-coordinates of the data points, must be increasing.
Run Code Online (Sandbox Code Playgroud)

List_CD不是在增加.

您可以通过以下方式对其进行排序:

d = dict(zip(List_CD, List_Dose))
xp = sorted(d)
yp = [d[x] for x in xp]
numpy.interp(2000., xp, yp)
# returns 21.791381359216665
Run Code Online (Sandbox Code Playgroud)

要么:

order = numpy.argsort(List_CD)
numpy.interp(2000., np.array(List_CD)[order], np.array(List_Dose)[order])
Run Code Online (Sandbox Code Playgroud)