python - scipy's interpn for interpolate high N data -


i try interpolate data using scipy.interpolate.interpn. might not right function, please advise me if it's not. need interpolate on 3 variables each have 2 values (8 in total) down single point.

here working example n=2 (i think).

from scipy.interpolate import interpn import numpy np points = np.zeros((2, 2)) points[0, 1] = 1 points[1, 1] = 1 values = np.array(([ 5.222, 6.916], [6.499, 4.102])) xi = np.array((0.108, 0.88))  print(interpn(points, values, xi))  # gives: 6.462 

but when try use higher dimension, breaks. have feeling because how arrays constructed.

p2 = np.zeros((2, 2, 2)) p2[0,0,1] = 1 p2[0,1,1] = 1 p2[1,0,1] = 1 p2[1,1,1] = 1 v2 = np.array([[[5.222,4.852],                 [6.916,4.377]],                [[6.499,6.076],                 [4.102,5.729]]]) x2 = np.array((0.108, 0.88, 1)) print(interpn(p2, v2, x2)) 

this gives me following error message:

/usr/local/lib/python2.7/dist-packages/scipy/interpolate/interpolate.pyc in interpn(points, values, xi, method, bounds_error, fill_value)    1680         if not np.asarray(p).ndim == 1:    1681             raise valueerror("the points in dimension %d must " -> 1682                              "1-dimensional" % i)    1683         if not values.shape[i] == len(p):    1684             raise valueerror("there %d points , %d values in "  valueerror: points in dimension 0 must 1-dimensional 

how fix code? keep in mind need interpolate on 3 variables 2 values in each (v2.shape = (2, 2, 2)).


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -