python - Scipy Griddata Output Dimensions -


i'm not sure i'm doing wrong. i'm attempting use scipy griddata interpolate data in irregular grid.

from scipy.interpolate import griddata 

i have 2 lists, "x" , "y", represent axes of original, uninterpolated grid. both lists of length 8.

then, make arrays represent axes of intended final, filled-in grid.

ny = np.linspace(0.0, max(y), y[len(y)-1]/min_interval+1) nx = np.linspace(0.0, max(x), len(ny)) 

i've checked , both "ny" , "nx" of shape (61,). then, create 8 x 8 list "z". finally, attempt make final grid.

z = griddata((np.array(x), np.array(y)), np.array(z), (nx, ny), method='nearest', fill_value=0) print z.shape 

the resulting 2d array has dimensions (61,8). tried using "x" , "y" lists , arrays - no change. why interpolating in 1 direction? expecting (61,61) array output. have included actual numbers if felt have been helpful, don't see how make difference. not understand how griddata works?

here full code:

import numpy np scipy.interpolate import griddata  # random data interpolate x = np.array([0, 10, 13, 17, 20, 50, 55, 60.0]) y = np.array([10, 20, 40, 80, 90, 95, 100, 120.0]) zg = np.random.randn(8, 8)  #select 1 of following 2 line, depends on order in z #xg, yg = np.broadcast_arrays(x[:, none], y[none, :])   xg, yg = np.broadcast_arrays(x[none, :], y[:, none])   yg2, xg2 = np.mgrid[y.min()-10:y.max()+10:100j, x.min()-10:x.max()+10:100j]  zg2 = griddata((xg.ravel(), yg.ravel()), zg.ravel(), (xg2.ravel(), yg2.ravel()), method="nearest") zg2.shape = yg2.shape  import pylab pl  pl.pcolormesh(xg2, yg2, zg2) pl.scatter(xg.ravel(), yg.ravel(), c=zg.ravel()) 

the output is:

enter image description here


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -