griddata doc:
In [47]: def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
....:
In [48]: points = np.random.rand(1000, 2)
In [49]: values = func(points[:,0], points[:,1])
In [50]: grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
, 1000 20 000.
In [52]: timeit interpolate.griddata(points, values, (grid_x, grid_y),
method='nearest')
10 loops, best of 3: 83.6 ms per loop
In [53]: timeit interpolate.griddata(points, values, (grid_x, grid_y),
method='linear')
1 loops, best of 3: 24.6 ms per loop
In [54]: timeit interpolate.griddata(points, values, (grid_x, grid_y),
method='cubic')
10 loops, best of 3: 42.7 ms per loop
:
In [55]: %%timeit
rbfi = interpolate.Rbf(points[:,0],points[:,1],values)
dl = rbfi(grid_x.ravel(),grid_y.ravel())
....:
1 loops, best of 3: 3.89 s per loop
In [56]: %%timeit
ndi=interpolate.NearestNDInterpolator(points, values)
dl=ndi(grid_x.ravel(),grid_y.ravel())
....:
10 loops, best of 3: 82.6 ms per loop
In [57]: %%timeit
ldi=interpolate.LinearNDInterpolator(points, values)
dl=ldi(grid_x.ravel(),grid_y.ravel())
....
10 loops, best of 3: 25.1 ms per loop
griddata .
griddata :
nearest
return the value at the data point closest to the point of
interpolation. See NearestNDInterpolator for more details.
Uses scipy.spatial.cKDTree
linear
tesselate the input point set to n-dimensional simplices,
and interpolate linearly on each simplex.
LinearNDInterpolator details are:
The interpolant is constructed by triangulating the
input data with Qhull [R37], and on each triangle
performing linear barycentric interpolation.
cubic (2-D)
return the value determined from a piecewise cubic, continuously
differentiable (C1), and approximately curvature-minimizing
polynomial surface. See CloughTocher2DInterpolator for more details.
, cKTtree ; .
, , .
Rbf, , . , , , .
.