apply gaussian filtering on numpy array with nan value and then plot the image
<p>I have a numpy 2d array (image) with values >=0.0 but there are some indices with value 'nan'. When I try to plot this figure it looks like the below image. The 0 in the image array becomes black and nan becomes white.</p>

<p><a href="http://i.stack.imgur.com/S5JHF.png" rel="nofollow"><img src="http://i.stack.imgur.com/S5JHF.png" alt="enter image description here"></a></p>

<p>Now I want to apply gaussian smoothing on this array such that the after smoothing when I try to plot smoothed array, the nan values from the previous array appears white only.</p>

<p>When doing a gaussian filter of an image, any pixel close to a <code>nan</code> pixel will also turn into a <code>nan</code>, since its new value is the weighted sum over all neighboring pixels covered by the convolution kernel.</p>

<p>Therefore, smoothing this particular image using, for example, <code>scipy.ndimage.filters.gaussian_filter()</code> will turn a lot of your zero values into <code>nan</code>s and you'll lose a lot of information.</p>

<p>To smooth this (apparently binary) data, I would replace the <code>nan</code>s by some other value, of course maintaining contrast to the non-<code>nan</code> pixels. For example, turn the zeros into ones, and the <code>nan</code>s into zeros, then apply the filter.</p>

python matplotlib