scipy-样条插值interpolate
[TOC]
python scipy样条插值函数:interpolate
interp1d 函数
class scipy.interpolate.interp1d
(x, y,kind=’linear’, axis=- 1**, copy=True, bounds_error=None, fill_value=nan, assume_sorted=False)**[source]
样条插值
- 样条插值法是一种以可变样条来作出一条经过一系列点的光滑曲线的数学方法。插值样条是由一些多项式组成的,每一个多项式都是由相邻的两个数据点决定的,这样,任意的两个相邻的多项式以及它们的导数(不包括仇阶导数)在连接点处都是连续的。 连接点的光滑与连续是样条插值和前边分段多项式插值的主要区别。
- 在Scipy里可以用
**scipy.interpolate模块下的interpld函数**
实现样条插值。 SciPy的0.14.0版本里样条插值方式有:'linear','zero', 'slinear', 'quadratic'(2次), 'cubic'(3次), 4, 5
等。 - scipy多次样条插值的应用格式如下所示:
1 | import matplotlib.pyplot as plt |
1 | import numpy as np, matplotlib.pyplot as plt |
scipy.interpolate.interp2d
class
scipy.interpolate.``interp2d
(x, y, z, kind=’linear’, copy=True, bounds_error=False, fill_value=None)[source]Interpolate over a 2-D grid.
x, y and z are arrays of values used to approximate some function f:
z = f(x, y)
. This class returns a function whose call method uses spline interpolation to find the value of new points.If x and y represent a regular grid, consider using RectBivariateSpline.Note that callinginterp2d
with NaNs present in input values results in undefined behaviour.Parametersx, yarray_like
Arrays defining the data point coordinates.If the points lie on a regular grid, x can specify the column coordinates and y the row coordinates, for example:
x = [0,1,2]; y = [0,3]; z = [[1,2,3], [4,5,6]]
Otherwise, x and y must specify the full coordinates for each point, for example:x = [0,1,2,0,1,2]; y = [0,0,0,3,3,3]; z = [1,2,3,4,5,6] `If x and y are multidimensional, they are flattened before use.`
z array_like
The values of the function to interpolate at the data points. If z is a multidimensional array, it is flattened before use. The length of a flattened z array is either len(x)len(y) if x and y specify the column and row coordinates or
len(z) == len(x) == len(y)
if x and y* specify coordinates for each point.kind{‘linear’, ‘cubic’, ‘quintic’}, optional
The kind of spline interpolation to use. Default is ‘linear’.
copybool, optionalIf True, the class makes internal copies of x, y and z.
If False, references may be used. The default is to copy.
bounds_errorbool, optional
If True, when interpolated values are requested outside of the domain of the input data (x,y), a ValueError is raised. If False, then fill_value is used.
fill_value number, optional
If provided, the value to use for points outside of the interpolation domain. If omitted (None), values outside the domain are extrapolated via nearest-neighbor extrapolation.
1 | from scipy import interpolate |