August 15, 2019 python metaphysics Modeling (5): interpolation (two-dimensional)

The official document link: https: //docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html#scipy.interpolate.interp2d

This blog scipy then the last one-dimensional interpolation, talk about the usage of two-dimensional interpolation api

scipy library may be implemented by one-dimensional interpolation based interp2d

类原型:class scipy.interpolate.interp2d(xyzkind='linear'copy=Truebounds_error=Falsefill_value=None)

Parameters are as follows:

x and y: x and y coordinates of the interpolation point. There are two specific wording, if x and y may be constituted by a Cartesian product grid (e.g. x = [1,2,3], y = [0,3]), then x and y would be considered grid , the number of interpolation points len (x) * len (y);

If not, then x and y must correspond to indicate the x and y coordinates of each of the interpolation points, the length of the x and y must be the same, such as x = [2,3,1], y = [0,0,4 ] it means (2,0), (3,0), (1,4) three interpolation points, the number of interpolation points len (x) or len (y);

If x and y are multidimensional, it will be automatically flattened;

z: z coordinates of interpolation points, the number of interpolation points consistent one-dimensional array (if it is multidimensional will automatically flattened), the length must be determined by the x and Y;

kind: interpolation method, there are three options, namely, 'linear' (linear interpolation), 'cubic' (cubic spline interpolation), 'quintic' (fifth spline interpolation);

copy, bounds_error, fill_value usage parameter and a three-dimensional interpolation is basically the same, but only the fixed stuff fill_value values ​​and extrapolation in two ways.

Dimensional interpolation api usage as a very simple, here is an example of official documentation are:

>>> from SciPy Import the interpolate
 >>> np.arange X = (-5.01, 5.01, 0.25 )
 >>> np.arange Y = (-5.01, 5.01, 0.25 )
 >>> XX, YY = np.meshgrid ( X, Y) # generated grid point, it can be directly understand the use of the investigation, a lot of information 
>>> Z = np.sin (XX + YY ** 2 ** 2 )
 >>> interpolate.interp2d = F (X, Y, Z, kind = ' Cubic ' )
 >>> Import matplotlib.pyplot AS PLT
 >>> np.arange Xnew = (-5.01, 5.01, 1E-2 )
 >>> np.arange ynew = (-5.01, 5.01 , 1E-2 )
 >>> znew = F (Xnew, ynew)
 >>> plt.plot (X, Z [0,:],' Ro- ', xnew, znew[0, :], 'b-')
>>> plt.show()

These are the simple use of interp2d.

Guess you like

Origin www.cnblogs.com/xsxsz/p/11361721.html