scipy.interpolate: 插值和平滑处理
scipy有很多插值函数(方法),按维度可分为一维、二维和多维的插值方法,按方法包括拉格朗日和泰勒插值方法等,具体插值函数可参阅如下介绍:
https://docs.scipy.org/doc/scipy/reference/interpolate.html?highlight=scipy%20interpolate#module-scipy.interpolate
一维插值
这里简单介绍下一维插值方法interpolate.interp1d
import numpy as np
from scipy.interpolate import interp1d
# 创建待插值的数据
x = np.linspace(0, 10 * np.pi, 20)
y = np.cos(x)
# 分别用linear和quadratic插值
fl = interp1d(x, y, kind='linear')
fq = interp1d(x, y, kind='quadratic') xint = np.linspace(x.min(), x.max(), 1000) # 将x设置为1000个点
yintl = fl(xint) # 线性插值
yintq = fq(xint) # 二次项插值
结果如图:
import matplotlib.pyplot as plt
fig,ax = plt.subplots(2,2,figsize=(10,8))
plt.subplot(221)
plt.plot(x,y,label='raw-data',marker='o')
plt.legend()plt.subplot(223)
plt.scatter(xint,yintl,label='linear_interpl',marker='o')
plt.legend()
plt.subplot(224)
plt.scatter(xint,yintq,label='quadratic_interpl',marker='o')
plt.legend()
平滑度
类似于曲线拟合,平滑度越高,滑动窗口取值越宽,曲线越平滑,具体参数可参考文档:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline
from scipy.interpolate import UnivariateSpline
x = np.linspace(-5,5,200)
y = np.exp(-x**2)+np.random.randn(200)/10# 平滑曲线处理,平滑参数s=1
s = UnivariateSpline(x,y,s=1)
xs = np.linspace(-5,5,1000)
ys = s(xs)
plt.plot(x,y,'.-')
plt.plot(xs,ys,label='s=1')
plt.legend()
plt.show()# 平滑曲线处理,平滑参数s=2
s = UnivariateSpline(x,y,s=2)
xs = np.linspace(-5,5,1000)
ys = s(xs)
plt.plot(x,y,'.-')
plt.plot(xs,ys,label='s=2')
plt.legend()
plt.show()
scipy.interpolate: 插值和平滑处理相关推荐
- scipy.interpolate插值
python SciPy库依赖于NumPy,提供了便捷且快速的N维数组操作. 可以实现插值,积分,优化,图像处理,特殊函数等等操作. 参考官方文档: Interpolation (scipy.int ...
- python插值(scipy.interpolate模块的griddata和Rbf)
1.插值scipy.interpolate SciPy的interpolate模块提供了许多对数据进行插值运算的函数,范围涵盖简单的一维插值到复杂多维插值求解. 一维插值:当样本数据变化归因于一个独立 ...
- 成功解决ImportError: cannot import name ‘spline‘ from ‘scipy.interpolate‘—利用make_interp_spline函数绘制平滑的曲线
成功解决ImportError: cannot import name 'spline' from 'scipy.interpolate'-利用make_interp_spline函数绘制平滑的曲线 ...
- python interpolate.interp1d_我如何使用scipy.interpolate.interp1d使用相同的X数组插值多个Y数组?...
例如,我有一个二维数据数组,其中一个维度上带有误差条,如下所示: In [1]: numpy as np In [2]: x = np.linspace(0,10,5) In [3]: y = np. ...
- matlab griddata插值太慢,非常慢的插值使用`scipy.interpolate.griddata`
在长期忍受scipy.interpolate.griddata极其缓慢的性能之后,我决定放弃{ 所以对于上面的例子,上面问题中的那个,你可以得到输入文件here,这是一段需要1.1ms的代码,而在上面 ...
- 对scipy.interpolate.make_interp_spline的理解
问题描述 记录今天看见代码里面用到scipy.interpolate.make_interp_spline()函数,主要学习https://blog.csdn.net/weixin_42782150/ ...
- python interpolate_python interpolate插值实例
我就废话不多说了,大家还是直接看代码吧~ import numpy as np #从scipy库中导入插值需要的方法 interpolate from scipy import interpolate ...
- scipy 三次样条插值
scipy 三次样条插值 文章目录 scipy 三次样条插值 scipy.interpolate.CubicSpline scipy.interpolate.PPoly scipy.interpola ...
- 如何优雅地平均多条曲线 scipy.interpolate.interp1d below the interpolation range error
正确的思路应该是得到所有曲线,然后规定新曲线采样位置(x坐标),然后平均y值.下面的做法错了,因为ROC曲线上的任一个点的位置是清晰地定义好的,插值是画蛇添足. ------------------- ...
最新文章
- 时隔16年,Science再次发布“全世界最前沿的125个科学问题”!
- shiro缓存管理时报错java.lang.ClassCastException: com.xxx.User cannot be cast to com.xxx.User
- 设定自动获得DNS服务器地址
- python中continue格式_python自学(3)--for 、 while、 break、continue、字符格式化输出...
- :nth-child和:nth-of-type之间的差异
- pytorch使用torch.nn.Sequential构建网络
- Python [6] IT资产管理(下)
- PHP能源管理系统ems,能源管理系统(EMS)方案.doc
- 怎样查询服务器中标信息,太极中标云服务器
- 2018湖南计算机对口高考C语言答案,2018年湖南省对口高考C语言试题
- dither(抖动)
- 实现 EC20 4G模块PPP拨号上网
- JavaScript 每日一题 #11
- js屏蔽手机的物理返回键
- OpenAI 推出漏洞赏金计划,最高奖励 2 万美元;京东零售开启 5 年来最大组织变革;​Django 4.2|极客头条
- PYTHON模块搜索路径
- 高等教育学:学生与教师
- Nacos 2.1.0 正式发布!堪称最强!
- 在使用ArcMap中的核密度分析时“输出像元大小”出现异常数的解决方案
- 转载 积分/C币获取方式