4
我想插入尺寸爲 的2D陣列「測試」爲8x8形狀的網格爲4x4(實際上接近1000x1000)。Python - 用於巨大陣列的插值2D陣列
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')
這很有效! ;)但對於我的情況,它似乎是那裏「太多的數據點插入」作爲錯誤:( – user3601754
你的新陣列有多大?也許你可以將它分成子數組來執行插值,然後然後將它們拼接在一起? – tom
例如,請參閱此[其他答案](http://stackoverflow.com/a/5329386/588071) – tom