[英]wrong interpolation in scipy.interpolate.interp1d
I have problem with scipy.interpolate.interp1d我对 scipy.interpolate.interp1d 有疑问
df =
ang frc
-40 -15605.47
-30 -16051.253
-20 -10895.4
-10 -6205.733
0 -1730.65
10 2697.85
20 7217.59
30 12022.48
40 17298.647
import pandas as pd
from scipy.interpolate import interp1d
df = pd.read_csv('111.txt', sep='\t')
print(df)
interpi = interp1d(df['frc'], df['ang'], fill_value='extrapolate')
print(interpi(-17000))
It gives import pandas as pd from scipy.interpolate import interp1d它从 scipy 导入 pandas 作为 pd.interpolate import interp1d
df = pd.read_csv('111.txt', sep='\t') print(df) interpi = interp1d(df['frc'], df['ang'], fill_value='extrapolate') print(interpi(-17000)) df = pd.read_csv('111.txt', sep='\t') print(df) interpi = interp1d(df['frc'], df['ang'], fill_value='extrapolate') 打印(interpi (-17000))
It gives -8.717 which is clearly wrong!
I rather it gives Error
can anyone help?
I think this depends on your definition of "wrong".我认为这取决于您对“错误”的定义。 To view this problem from the perspective of the interpolator (or rather extrapolator): If
x_new = - 17000
, ie, outside of the range, the following points (blue in the picture below) are used to extrapolate: (-15605.47, -40)
and (-16051.253, -30)
.从插值器(或者更确切地说是外插器)的角度来看这个问题: 如果
x_new = - 17000
,即超出范围,则使用以下点(下图中的蓝色)进行外推: (-15605.47, -40)
和(-16051.253, -30)
。 From those, the interpolator learns that a decrease in frc
leads to an increase in ang
.从中,插值器了解到
frc
的减少会导致ang
的增加。 See the following picture.请参见下图。 I clipped interpolation range for visibility.
为了可见性,我剪掉了插值范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.