首页 > 解决方案 > 在python中进行样条插值的更快方法

问题描述

我正在尝试用 3 度样条插值 30 个点,如下所示:

from sympy import interpolating_spline
domain_points = [0.01, 0.01888888888888889, 0.027777777777777776, 0.03666666666666667, 0.04555555555555556, 0.05444444444444445, 0.06333333333333332, 0.07222222222222222, 0.0811111111111111, 0.09, 0.09888888888888889, 0.10777777777777778, 0.11666666666666665, 0.12555555555555556, 0.13444444444444445, 0.14333333333333334, 0.15222222222222223, 0.16111111111111112, 0.17, 0.30833333333333335, 0.44666666666666666, 0.5850000000000001, 0.7233333333333334, 0.8616666666666667, 1.0, 2.5, 4.0, 5.5, 7.0, 8.5]
range_points = list(map(lambda x: x-1/x, domain_points))

interpolating_spline(3, x, domain_points, range_points)

这在我的机器上大约需要 1 分钟 42 秒。我做错了什么让这这么慢吗?有没有办法加快速度,或者有一个更快的样条插值库,这样我就可以插值更多的点?

标签: pythonsympy

解决方案


如果您只想数字插值,请使用 scipy

https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html#spline-interpolation

Sympy 用于代数操作。


推荐阅读