python一维插值scipy.interpolate.interp1d

python一维插值scipy.interpolate.interp1d

2023年6月29日发(作者:)

python⼀维插值1d SciPy的interpolate模块提供了许多对数据进⾏插值运算的函数,范围涵盖简单的⼀维插值到复杂多维插值求解。当样本数据变化归因于⼀个独⽴的变量时,就使⽤⼀维插值;反之样本数据归因于多个独⽴变量时,使⽤多维插值。class

1d(x,

y,

kind='linear',

axis=-1,

copy=True,

bounds_error=None,

fill_value=nan,

assume_sorted=False)Interpolate a 1-D function.x and

y are arrays of values used to approximate some function f: y = f(x). This class returns a function whose call methoduses interpolation to find the value of new points.x和y是⽤来逼近函数f: y = f(x)的值的数组。该类返回⼀个函数,该函数的调⽤⽅法使⽤插值表达式来查找新点的值。Note that calling with NaNs present in input values results in undefined behaviour.注意,使⽤在输⼊值中出现的NaNs调⽤interp1d会导致未定义的⾏为。Parametersx(N,) array_likeA 1-D array of real values.实值的⼀维数组。y(…,N,…) array_likeA N-D array of real values. The length of

y along the interpolation axis must be equal to the length of

x.实值的N-D数组。沿插补轴的y的长度必须等于x的长度。kind str or int, optionalSpecifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’,‘previous’, ‘next’, where ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first,second or third order; ‘previous’ and ‘next’ simply return the previous or next value of the point) or as an integerspecifying the order of the spline interpolator to use. Default is ‘linear’.指定插值类型为⼀个字符串(' linear ', ' nearest ', 'zero ', ' slinear ', ' second ', ' cubic ', ' previous ', ' next ',其中' zero ', ' slinear ', ' second ' and ' cubic '指的是插值为零、⼀阶、⼆阶或三阶的样条曲线;' previous '和' next '简单地返回该点的上⼀个或下⼀个值),或者作为⼀个整数指定样条插值器使⽤的顺序。默认设置是“线性”。候选值‘zero’ 、'nearest'‘slinear’ 、'linear'‘quadratic’ 、'cubic'作⽤阶梯插值,相当于0阶B样条曲线线性插值,⽤⼀条直线连接所有的取样点,相当于⼀阶B样条曲线⼆阶和三阶B样条曲线,更⾼阶的曲线可以直接使⽤整数值指定axis int, optionalSpecifies the axis of

y along which to interpolate. Interpolation defaults to the last axis of

y.指定要沿其插⼊的y轴。插值默认是y的最后⼀个轴。copy bool, optionalIf True, the class makes internal copies of x and y. If False, references to

x and

y are used. The default is to copy.如果为真,则该类将创建x和y的内部副本。如果为假,则使⽤对x和y的引⽤。默认是复制。bounds_error bool, optionalIf True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation isnecessary). If False, out of bounds values are assigned . By default, an error is raised unless fill_value="extrapolate".如果为真,则在试图对x范围之外的值进⾏插值时(需要外推的地⽅)会产⽣ValueError。如果为假,则为越界值分配fill_value。默认情况下,除⾮fill_value="extrapolate",否则将引发⼀个错误。fill_value array-like or (array-like, array_like) or “extrapolate”, optionalif a ndarray (or float), this value will be used to fill in for requested points outside of the data range. If not provided,then the default is NaN. The array-like must broadcast properly to the dimensions of the non-interpolation axes.如果是ndarray(或float),则此值将⽤于填充数据范围之外的请求点。如果没有提供,那么缺省值是NaN。类数组必须正确地传播到⾮插值轴的维度。If a two-element tuple, then the first element is used as a fill value for x_new < x[0] and the second element is usedforx_new > x[-1]. Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a singlearray-like argument meant to be used for both bounds asbelow, above = fill_value, fill_value.如果是双元素元组,则第⼀个元素⽤作x_new < x[0]的填充值,第⼆个元素⽤作forx_new > x[-1]。任何⾮2元素元组(例如list或ndarray,⽆论其形状如何)的内容都被视为⼀个类似数组的参数,⽤于下⾯、上⾯的两个边界= fill_value、fill_value。New in version “extrapolate”, then points outside the data range will be extrapolated.如果“外推”,则外推数据范围之外的点。New in version _sorted bool, optionalIf False, values of

x can be in any order and they are sorted first. If True,

x has to be an array of monotonically increasingvalues.如果为假,则x的值可以是任意顺序的,并且可以先排序。如果为真,则x必须是⼀个值单调递增的数组。>>> import numpy as np>>> import as pl>>> from olate import interp1d>>>

>>> x=ce(0,10,11)>>> y=(x)>>> xarray([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])>>> yarray([ 0. , 0.84147098, 0.90929743, 0.14112001, -0.7568025 , -0.95892427, -0.2794155 , 0.6569866 , 0.98935825, 0.41211849, -0.54402111])>>> (x,y,"o")[<2D object at 0x000000000AE3BF48>]>>> ()>>> x_new = ce(0, 10, 101)>>> x_newarray([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3. , 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4. , 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6. , 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7. , 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8. , 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9. , 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10. ])>>>

>>> kind_lst = ['nearest', 'zero', 'slinear', 'cubic', 'previous', 'next']>>> for k in kind_lst: f = interp1d(x,y,kind=k) y_new = f(x_new) (x_new, y_new, label=k)

[<2D object at 0x000000000F74CE08>][<2D object at 0x000000000F6FF948>][<2D object at 0x000000000DC41908>][<2D object at 0x000000000F757FC8>][<2D object at 0x000000000F6FF808>][<2D object at 0x000000000F6F3908>]>>>

>>> (loc="lower right")< object at 0x000000000DEC9C08>>>> ()>>>

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687977152a62826.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信