python——numpy中插值函数interp的使⽤⼩记录
def interp(x, xp, fp, left=None, right=None, period=None):
Parameters
----------
x : array_like
The x-coordinates at which to evaluate the interpolated values.
xp :1-D sequence of floats
The x-coordinates of the data points, must be increasing if argument
`period` is not specified. Otherwise, `xp` is internally sorted after
normalizing the periodic boundaries with ``xp = xp % period``.
fp :1-D sequence of float or complex
The y-coordinates of the data points, same length as `xp`.
left : optional float or complex corresponding to fp
Value to return for `x < xp[0]`, default is `fp[0]`.
right : optional float or complex corresponding to fp
Value to return for `x > xp[-1]`, default is `fp[-1]`.
period :None or float, optional
A period for the x-coordinates. This parameter allows the proper
interpolation of angular x-coordinates. Parameters `left` and `right`
are ignored if `period` is specified.
.. versionadded::1.10.0
Returns
-
------
y :float or complex(corresponding to fp)or ndarray
The interpolated values, same shape as `x`.
其实我个⼈看了这些参数也是很容易记乱的。
多看看例⼦可能更容易理解,使⽤实例:
import numpy as np
if __name__ =='__main__':
# lam1是原始数据坐标
lam1 =[0,2]
# lam2是你想要插值到的数据坐标
lam2 = np.linspace(0,2,3)
linspace numpyy =[0,0.95]
#将横坐标【0,2】的数据插值到【0,1,2】
l = np.interp(lam2, lam1, y)
print(l)
输出结果:
⾄于参数left和right,是当你要插值的x⼩于已有的x或⼤于已有的x时,插⼊的值要被设置成left或right。默认是已有数组的最左边值和最右边值。
默认情况下:
lam1 =[1,3]
# lam2是你想要插值到的数据坐标
lam2 = np.linspace(0,4,5)
y =[0,0.95]
l = np.interp(lam2, lam1, y,left=0.5,right=0.5)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论