【发布时间】:2021-10-23 00:00:34
【问题描述】:
我想插入二维数组“测试”,其维度 是 4x4(例如,实际上接近 1000x1000),网格形状为 8x8。
import numpy as np
X = np.arange(0,4,1)
Y = np.arange(0,4,1)
points = np.vstack((X,Y))
points = points.T #my coordinates
#my values as a 2D array
test = np.array([[ 1.2514318 , 1.25145821, 1.25148472, 1.25151133],
[ 1.25087456, 1.25090105, 1.25092764, 1.25095435],
[ 1.25031581, 1.25034238, 1.25036907, 1.25039586],
[ 1.24975557, 1.24978222, 1.24980898, 1.24983587]])
我尝试使用 griddata,但它似乎只适用于 1D 不是吗?正如错误告诉我的那样,我有“不同数量的值和点”我犯了错误吗?
from scipy.interpolate import griddata
grid_x, grid_y = np.mgrid[0:4:8j, 0:4:8j]
grid_z0 = griddata(points, test, (grid_x, grid_y), method='linear')
【问题讨论】:
标签: python arrays numpy interpolation