METPY
https://unidata.github.io/MetPy/latest/examples/gridding/Point_Interpolation.html?highlight=point
SCIPY
https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
from scipy.interpolate import griddata
import numpy as np
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
grid_x, grid_y = np.mgrid[0:1:50j, 0:1:100j]
points = np.random.rand(1000, 2)
x=points[:,0]
y=points[:,1]
print(x)
print(points.shape)
print(grid_x.shape)
print(grid_y.shape)
values = func(points[:,0], points[:,1])
#print(grid_x)
#print(points[:,0])
print(values.shape)
grid_z0 = griddata((x,y), values, (grid_x, grid_y), method='nearest')
grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')
print(grid_z0.shape)
print(grid_z1.shape)
print(grid_z2.shape)
(1000, 2)# 对numpy.meshgrid()理解## numpy.meshgrid()理解
(50, 100)
(50, 100)
(1000,) ##只有一列
(50, 100)
(50, 100)
(50, 100)
网友评论