[SciPy-user] best way to interpolate NAN's in 3d array

Vincent Schut schut@sarvision...
Wed Jan 16 08:23:02 CST 2008

Hi guru's,

Let's say I have a (25,50,50) array, with approximately half of the
items filled, half of them NAN due to missing input data. Could someone
suggest a good way to interpolate/fill these NAN's?

What I'm doing currently is using scipy.ndimage.generic_filter with a
averaging 3x3x3 filter, running it recursively till all NAN's are gone.
This worked fine for my prototyping arrays of 10x10x10, with 25x50x50
however things are kind of slow.

As you can see, the accuracy of the interpolation is not very important
(my implementation has lots of drawbacks compared to 'real'
interpolation). Issue is I want to use the result to use
ndimage.map_coordinates on, which will always return NAN whenever a NAN
was close to the coordinates mapped to... So the main issue is to get
rid of those NAN's, and fill them with more or less the
average/interpolation of the surrounding known values. Or get a NAN- or
maskedarray sensitive replacement for map_coordinates :-)

Vincent Schut.

More information about the SciPy-user mailing list