gpt4 book ai didi

python - Python 中的 interp2d 函数运行时错误

转载 作者:行者123 更新时间:2023-12-01 00:46:59 26 4
gpt4 key购买 nike

我有以下数据,在 MATLAB 中可以使用 interp2 函数轻松对这些数据进行插值。但是在Python中使用interp2d时,会遇到以下错误:

RuntimeWarning: No more knots can be added because the number of B-spline
coefficients already exceeds the number of data points m.
Probable causes: either s or m too small. (fp>s)
kx,ky=3,3 nx,ny=17,11 m=90 fp=0.000013 s=0.000000
warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess))

我尝试过使用griddata,但最终也没有运气。如果能解决这些问题,我们将不胜感激。

代码:

OF_S = np.array([[5, 5, 5, 5, 5, 5, 5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5,     5],
[6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
[7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]])

FT_FTAVAIL_S = np.array([[0.198, 0.205, 0.214, 0.227, 0.237, 0.249, 0.26, 0.271, 0.285, 0.304, 0.332, 0.371, 0.405, 0.436, 0.464, 0.507, 0.548, 0.598, 0.649, 0.694, 0.746, 0.787, 0.822, 0.851, 0.879, 0.914, 0.951, 0.985, 0.999, 1],
[0.198, 0.205, 0.214, 0.227, 0.237, 0.249, 0.26, 0.271, 0.285, 0.304, 0.332, 0.371, 0.405, 0.436, 0.464, 0.507, 0.548, 0.598, 0.649, 0.694, 0.746, 0.787, 0.822, 0.851, 0.879, 0.914, 0.951, 0.985, 0.999, 1],
[0.198, 0.205, 0.214, 0.227, 0.237, 0.249, 0.26, 0.271, 0.285, 0.304, 0.332, 0.371, 0.405, 0.436, 0.464, 0.507, 0.548, 0.598, 0.649, 0.694, 0.746, 0.787, 0.822, 0.851, 0.879, 0.914, 0.951, 0.985, 0.999, 1.000]])

ISP_ISPAVAIL_S = np.array([[0.9845, 0.9867, 0.9867, 0.9867, 0.9867, 0.9889, 0.9889, 0.9889, 0.9889, 0.9911, 0.9911, 0.9933, 0.9933, 0.9956, 0.9956, 0.9956, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 0.9978, 1, 1, 1, 1],
[0.9756, 0.9756, 0.9761, 0.9778, 0.9778, 0.9778, 0.9787, 0.9798, 0.98, 0.9804, 0.9827, 0.9844, 0.9855, 0.9867, 0.9889, 0.9892, 0.9911, 0.9927, 0.9933, 0.9942, 0.9956, 0.9956, 0.9978, 0.9978, 0.9978, 0.9978, 0.9988, 1, 1, 1],
[0.9662, 0.9662, 0.9662, 0.9679, 0.9685, 0.9697, 0.9707, 0.9709, 0.972, 0.9738, 0.9755, 0.9797, 0.9805, 0.982, 0.9842, 0.9863, 0.9873, 0.9887, 0.991, 0.992, 0.9932, 0.9943, 0.9955, 0.9955, 0.9966, 0.9977, 0.9978, 0.9986, 0.9999, 1]])

ISP_ISPAVAIL_interpGrid = interp2d(FT_FTAVAIL_S, OF_S, ISP_ISPAVAIL_S, kind='cubic')

最佳答案

我最终使用了 griddata。这里的关键是在进行任何插值之前对数据进行扁平化。因此我使用 .ravel() 来做到这一点。

ISP_ISPAVAIL= griddata(
(FT_FTAVAIL_S.ravel(), OF_S.ravel()), ISP_ISPAVAIL_S.ravel(), (XX, YY), method="nearest")

其中 XX 和 YY 分别是 FT_FTAVAIL_S 和 OF_S 的任意边界。

关于python - Python 中的 interp2d 函数运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56895687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com