N-dimensional linear interpolation in Python (evaluating an array using a boolean index)

Suppose I have an N-dimensional array ar

with ar.shape=(n1,...,nN)

. Is there a python module that allows evaluating ar

at a boolean index?

As an example, suppose: ar.shape=(3,4,5)

. Then I look for a function f

that does this:result=f(ar,[2.3,1.5,3.4])

+3


source to share


2 answers


From the docs scipy: scipy.interpolate.griddata

: Interpolate unstructured N-dimensional data .



+3


source


scipy.ndimage.map_coordinates is quick and easy;
see the 2d example in multivariate-spline-interpolation-in-python-scipy .

( map_coordinates( ... order=1 )

this is what you are asking for - Bilinear_interpolation in 2d, trilinear in 3d ...
order=0

is the closest grid point, order=2

or 3 - look (order + 1) ^ d points - slower and smoother.)



Added: as you probably know, numpy rounds float indices before ints:

A = np.eye( 3 )
print A[ 0.1, 0.9 ], A[ 1.1, 2.9 ]

      

+2


source







All Articles