python一维插值scipy.interpolate.interp1d

python一维插值scipy.interpolate.interp1dSciPy的interpolate模块提供了许多对数据进行插值运算的函数,范围涵盖简单的一维插值到复杂多维插值求解。当样本数据变化归因于一个独立的变量时,就使用一维插值;反之样本数据归因于多个独立变量时,使用多维插值。classscipy.interpolate.interp1d(x,y,kind=’linear’,axis=-1,copy=True,bounds_…

大家好,又见面了,我是你们的朋友全栈君。

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

class scipy.interpolate.interp1d(xykind=’linear’axis=-1copy=Truebounds_error=Nonefill_value=nanassume_sorted=False)[source]

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 method uses interpolation to find the value of new points.x和y是用来逼近函数f: y = f(x)的值的数组。该类返回一个函数,该函数的调用方法使用插值表达式来查找新点的值。

Note that calling interp1d with NaNs present in input values results in undefined behaviour.注意,使用在输入值中出现的NaNs调用interp1d会导致未定义的行为。

Parameters

x(N,) array_like

A 1-D array of real values.实值的一维数组。

y(…,N,…) array_like

A 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, optional

Specifies 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 integer specifying 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’ 阶梯插值,相当于0阶B样条曲线
‘slinear’ 、’linear’ 线性插值,用一条直线连接所有的取样点,相当于一阶B样条曲线
‘quadratic’ 、’cubic’ 二阶和三阶B样条曲线,更高阶的曲线可以直接使用整数值指定

axis int, optional

Specifies the axis of y along which to interpolate. Interpolation defaults to the last axis of y.指定要沿其插入的y轴。插值默认是y的最后一个轴。

copy bool, optional

If 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, optional

If True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If False, out of bounds values are assigned fill_value. 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”, optional

  • if 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 used forx_new > x[-1]. Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a single array-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 0.17.0.

  • If “extrapolate”, then points outside the data range will be extrapolated.如果“外推”,则外推数据范围之外的点。

    New in version 0.17.0.

assume_sorted bool, optional

If False, values of x can be in any order and they are sorted first. If True, x has to be an array of monotonically increasing values.如果为假,则x的值可以是任意顺序的,并且可以先排序。如果为真,则x必须是一个值单调递增的数组。

>>> import numpy as np
>>> import matplotlib.pyplot as pl
>>> from scipy.interpolate import interp1d
>>> 
>>> x=np.linspace(0,10,11)
>>> y=np.sin(x)
>>> x
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])
>>> y
array([ 0.        ,  0.84147098,  0.90929743,  0.14112001, -0.7568025 ,
       -0.95892427, -0.2794155 ,  0.6569866 ,  0.98935825,  0.41211849,
       -0.54402111])
>>> pl.plot(x,y,"o")
[<matplotlib.lines.Line2D object at 0x000000000AE3BF48>]
>>> pl.show()

python一维插值scipy.interpolate.interp1d

>>> x_new = np.linspace(0, 10, 101)
>>> x_new
array([ 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)
	pl.plot(x_new, y_new, label=k)

	
[<matplotlib.lines.Line2D object at 0x000000000F74CE08>]
[<matplotlib.lines.Line2D object at 0x000000000F6FF948>]
[<matplotlib.lines.Line2D object at 0x000000000DC41908>]
[<matplotlib.lines.Line2D object at 0x000000000F757FC8>]
[<matplotlib.lines.Line2D object at 0x000000000F6FF808>]
[<matplotlib.lines.Line2D object at 0x000000000F6F3908>]
>>> 
>>> pl.legend(loc="lower right")
<matplotlib.legend.Legend object at 0x000000000DEC9C08>
>>> pl.show()
>>> 

python一维插值scipy.interpolate.interp1d

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/133423.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Cordova App 打包全揭秘

    本文作者:大师兄(高武军)现就职于某公司移动端架构师兼产品开发。主要开发产品:mdn(适配app和微信的移动端解决方案),pageui(移动端ui组件库),formBuilder(可以让前端建表和操作表的表单设计器)。课程介绍点击查看原文Cordova是一个开源的移动开发框架。允许你用标准的Web技术——HTML5,CSS3和JavaScript做跨平台开发。应用在每个平台的

    2022年4月7日
    71
  • JAVA Applet小应用程序入门

    JAVA Applet小应用程序入门1.Applet如何运行不同于java应用程序,运行applet需要在对应html文件通过&lt;applet&gt;指定applet程序名,即可在浏览器中运行.2.Applet如何编写我的工具是eclipse。新建一个类该类必须是public且继承Applet。文件名与类名一样3.Applet类中方法的执行顺序与生命周期先执行构造方法 再执行init()进行一些数…

    2022年7月8日
    21
  • ideatomcat日志乱码_tomcat 日志

    ideatomcat日志乱码_tomcat 日志1、tomacat日志有三个地方,分布时Output(控制台)、TomcatLocalhostLog(tomcat本地日志)、TomcatCatalinaLog。启动日志和大部分报错日志、普通日志都在output打印;有些错误日志,在TomcatLocalhostLog。三个日志显示区,都可能出现乱码现象。2、解决方案一:首先,找到本地tomcat的conf目录下的logging.properties,这个文件中有5个编码的位置1)对于控制台output报错的情况,将下图位置

    2022年9月26日
    1
  • touchpoint_pointpillars

    touchpoint_pointpillars理想如果不向现实做一点点屈服,那么理想也将归于尘土。锚点的简介在SpriteKit的游戏开发当中经常会使用到AnchorPoint这一属性,锚点的使用一般是配合着position属性使用的,锚点是在自身View上找,这个点一一映射的有一个父view的坐标(使用position来表示),可以通过这两个值来计算子视图的位置信息.也就是说position用来设置CALayer在父层中的位置,而anchorPoint决定着CALayer身上的哪个点会在position属性所指的位置.coco.

    2022年10月8日
    0
  • AIC,BIC信息准则

    AIC,BIC信息准则AIC,BIC信息准则用于判断哪个模型比较好,具体计算公式如下:1.AICAIC=-2In(L)+2k其中L指对应的最大似然函数,k指对应的模型的变量的个数。2.BICBIC=-2In(L)+In(n)*kn指对应的数据数量,L和k同上所述。kln(n)惩罚项在维数过大且训练样本数据相对较少的情况下,可以有效避免出现维度灾难现象。AIC,BIC越小越好。…

    2022年5月23日
    55
  • 人脸识别系统如何建模_3dmax人脸建模

    人脸识别系统如何建模_3dmax人脸建模本发明涉及生物特征识别,特别是涉及人脸识别中的特征建模方法。背景技术:人脸识别技术一般包括四个组成部分,分别为人脸图像采集、人脸图像预处理、人脸图像特征提取以及匹配与识别,具体来说:人脸图像采集及检测是指通过摄像镜头等视频图像采集装置采集包括有人脸的视频或图像数据,可以是采集对象的静态图像、动态图像、不同的位置、不同表情等。人脸图像预处理是指从采集的图像数据中确定人脸的部分,并进行灰度校正、噪声过…

    2022年9月17日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号