title: How to apply a uniform filter using SciPy Image where the data outside the boundary is not tallied?
body: <p>I have spent lots of time on this, and I know how to manually do it by slicing and indexing the boundary rows/cols, but there has to be a simpler way with SciPy.</p>
  
  <p>I need to set the <code>CVAL</code> (values to fill past the edges when <code>mode=constant</code>) to NaN, however, this will return NaN.</p>
  
  <p>I will explain it with code and figures:</p>
  
  <pre><code>import numpy as np
  from scipy import ndimage
  m = np.reshape(np.arange(0,100),(10,10)).astype(np.float)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nV8Lj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nV8Lj.png" alt="picture of the input array"></a>
  Use SciPy ndimage uniform filter to calculate the mean using a 3x3 kernel:</p>
  
  <pre><code>filter = ndimage.uniform_filter(m, size=3, mode='constant')
  print(filter[1][1]) # equal to 11
  print(filter[9][9]) # I need 93.5, however it gets 41.55 due to zeros
  </code></pre>
  
  <p>As you can see, the first value comes out as 11, which is as expected,
  however, for any cell along the border, it will fill the values with zero (I have also tried all the other modes).</p>
  
  <p>Here is what I need to achieve (left) vs <code>mode=constant</code> and <code>CVAL=0</code> (default 0)</p>
  
  <p><a href="https://i.stack.imgur.com/1CtDx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1CtDx.png" alt="scipy avg and what I need"></a></p>