title: Nested for loop to numpy convolve
body: <p>How can I improve the speed of this function?</p>
  
  <pre><code>def foo(mri_data, radius):
  
      mask = mri_data.copy()
  
      ny = len(mri_data[0,:])
      nx = len(mri_data[:])
  
      for y in xrange(0, ny):
          for x in xrange(0, nx):
              if (mri_data[x-radius:x+radius,y-radius:y+radius] != 1.0).all():
                  mask[x,y] = 0.0                    
      return mask.copy() 
  </code></pre>
  
  <p>It takes in image slices in the form of a numpy array. Iterates through each pixels and tests a bounding box around that pixel. If no values in the box are equal to 1 than we discard that pixel by setting it to 0. </p>
  
  <p>I've been told I can use <code>numpy.convolve</code> but I am uncertain how this relates.</p>
  
  <p>EDIT: The images values are in binary range so lowest value is 0.0 and max value is 1.0. With values in between ex: 0.767. </p>