日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

scipy.interpolate: 插值和平滑处理

發布時間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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: 插值和平滑处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。