[Numpy-discussion] How to median filter a masked array?

Russell E Owen rowen at u.washington.edu
Wed Jul 14 08:48:07 CDT 2004


I want to 3x3 median filter a masked array (2-d array of ints -- an 
astronomical image), where the masked data and points off the edge 
are excluded from the local median calculation. Any suggestions for 
how to do this efficiently? I suspect I have to write it in C, which 
is an unpleasant prospect.

I tried using NaN for points to mask out, but the median filter seems 
to handle those as "infinity", or something equally inappropriate.

In a related vein, has Python come along far enough that it would be 
reasonable to add support for NaN to numarray -- in the sense that 
statistics calculations, filters, etc. could be convinced to ignore 
NaNs? Obviously this support would be contingent on compiling python 
with IEEE floating point support, but I suspect that's the default on 
most platforms these days.

-- Russell




More information about the Numpy-discussion mailing list