[SciPy-User] scipy.ndimage.filters.median_filter with NAN values
Warren Weckesser
warren.weckesser at gmail.com
Fri Oct 10 22:34:16 EDT 2014
On Fri, Oct 10, 2014 at 2:43 PM, Shahar Barak <shaharb at stanford.edu> wrote:
> I have a 3D array, in which some values are Nan (masked).
> I am using scipy.ndimage.filters.median_filter to smooth the data.
> Is there a way to have scipy.ndimage.filters.median_filter not include the
> NAN values in its median calculation?
>
>
You could use scipy.ndimage.filters.generic_filter, with np.nanmedian as
the 'function' argument, but it will be painfully slow compared to
median_filter. E.g.
In [97]: x = np.random.randn(50, 50, 50)
In [98]: %timeit median_filter(x, size=3)
10 loops, best of 3: 47.9 ms per loop
In [99]: %timeit generic_filter(x, np.nanmedian, size=3)
1 loops, best of 3: 2.21 s per loop
That's about 46 times slower for an array with shape (50, 50, 50).
Warren
Thanks,
>
> Shahar
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20141010/11c6cbc5/attachment.html>
More information about the SciPy-User
mailing list