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: 插值和平滑处理相关推荐

  1. scipy.interpolate插值

    python  SciPy库依赖于NumPy,提供了便捷且快速的N维数组操作. 可以实现插值,积分,优化,图像处理,特殊函数等等操作. 参考官方文档: Interpolation (scipy.int ...

  2. python插值(scipy.interpolate模块的griddata和Rbf)

    1.插值scipy.interpolate SciPy的interpolate模块提供了许多对数据进行插值运算的函数,范围涵盖简单的一维插值到复杂多维插值求解. 一维插值:当样本数据变化归因于一个独立 ...

  3. 成功解决ImportError: cannot import name ‘spline‘ from ‘scipy.interpolate‘—利用make_interp_spline函数绘制平滑的曲线

    成功解决ImportError: cannot import name 'spline' from 'scipy.interpolate'-利用make_interp_spline函数绘制平滑的曲线 ...

  4. 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. ...

  5. matlab griddata插值太慢,非常慢的插值使用`scipy.interpolate.griddata`

    在长期忍受scipy.interpolate.griddata极其缓慢的性能之后,我决定放弃{ 所以对于上面的例子,上面问题中的那个,你可以得到输入文件here,这是一段需要1.1ms的代码,而在上面 ...

  6. 对scipy.interpolate.make_interp_spline的理解

    问题描述 记录今天看见代码里面用到scipy.interpolate.make_interp_spline()函数,主要学习https://blog.csdn.net/weixin_42782150/ ...

  7. python interpolate_python interpolate插值实例

    我就废话不多说了,大家还是直接看代码吧~ import numpy as np #从scipy库中导入插值需要的方法 interpolate from scipy import interpolate ...

  8. scipy 三次样条插值

    scipy 三次样条插值 文章目录 scipy 三次样条插值 scipy.interpolate.CubicSpline scipy.interpolate.PPoly scipy.interpola ...

  9. 如何优雅地平均多条曲线 scipy.interpolate.interp1d below the interpolation range error

    正确的思路应该是得到所有曲线,然后规定新曲线采样位置(x坐标),然后平均y值.下面的做法错了,因为ROC曲线上的任一个点的位置是清晰地定义好的,插值是画蛇添足. ------------------- ...

最新文章

  1. 使用Python,OpenCV线程化方式提高视频FPS(每秒帧数)
  2. android activity启动流程_Activity 启动流程(二)
  3. 学习deercao的正则笔记
  4. 修改 VS2013 项目属性的默认包含路径(全局)
  5. python的回收机制_Python垃圾回收机制【人生苦短,我用python】-阿里云开发者社区...
  6. HDU 5869.Different GCD Subarray Query-区间gcd+树状数组 (神奇的标记右移操作) (2016年ICPC大连网络赛)...
  7. java合并sheet行_java poi Excel循环合并行
  8. 佳能相机CR2转TIFF
  9. 弹窗修改数据 临时解决方法 + ajax
  10. 应用程序热补丁(三):完整的设计与实现
  11. LINUX下调节屏幕亮度(Intel核显)-续
  12. 滑动门技术的详细分析
  13. 【echarts 中国地图】vue实现中国地图,省份居中china.json文件下载
  14. 尔雅 科学通史(吴国盛) 个人笔记及课后习题 2018 第七章 实验传统的兴起
  15. R绘图笔记 | 生存曲线的绘制
  16. 【工具】推荐一个轻量级视频播放器——MPC-HC
  17. C++ 鼠标模拟程序
  18. 在VMware上如何创建虚拟机并安装linux操作系统,以及虚拟机的账户密码破解
  19. [每日一氵] BERT下游二分类任务精确率P约为0.5,召回率R约为1的问题
  20. Pytorch实战:8层神经网络实现Cifar-10图像分类验证集准确率94.71%

热门文章

  1. oracle簇表 数据抽取,Oracle聚簇表
  2. icd植入是大手术吗_白内障手术为何要植入人工晶体?便宜的人工晶体会影响视力吗?...
  3. python中可以作为定界符_在 Python 中,字典和集合都是用一对 作为定界符,字典的每个元素有两部分组成,即 和 ,其中 不允许重复。_学小易找答案...
  4. 涂鸦之作WanAndroid第三方APP
  5. linux 下设置定时任务
  6. 胡凌:隐私的终结——大数据时代的个体生活危机
  7. 使用的postman心得
  8. console的高级使用
  9. nginx图片过滤处理模块http_image_filter_module
  10. 揭秘:下一代的VisualStudio将会怎样?