title: Find all points within distance 1 of specific point in 2D numpy matrix
body: <p>I want to <strong>find a list of points that are within range 1 (or exactly diagonal) of a point in my numpy matrix</strong>:</p>
  
  <p>For example say my matrix <code>m</code> is:</p>
  
  <pre><code>[[0 0 0 0 0]
   [0 0 0 0 0]
   [0 0 1 0 0]
   [0 0 0 0 0]
   [0 0 0 0 0]] 
  </code></pre>
  
  <p>I would like to obtain a list of tuples or something representing all the coordinates of the 9 points with X's below:</p>
  
  <pre><code>[[0 0 0 0 0]
   [0 X X X 0]
   [0 X X X 0]
   [0 X X X 0]
   [0 0 0 0 0]]
  </code></pre>
  
  <p>Here is another example with the target point on the edge:</p>
  
  <pre><code>[[0 0 0 0 0]
   [0 0 0 0 0]
   [0 0 0 0 1]
   [0 0 0 0 0]
   [0 0 0 0 0]] 
  </code></pre>
  
  <p>In this case there would only 6 points within distance 1 of the target point:</p>
  
  <pre><code>[[0 0 0 0 0]
   [0 0 0 X X]
   [0 0 0 X X]
   [0 0 0 X X]
   [0 0 0 0 0]] 
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Using David Herrings answer/comment about chebyshev distance here is my attempt to solve example 2 above assuming I know the coordinates of the target point:</p>
  
  <pre><code>from scipy.spatial import distance
  
  point = [2, 4]
  valid_points = []
  for x in range(5):
    for y in range(5):
      if(distance.chebyshev(point, [x,y]) &lt;= 1):
        valid_points.append([x,y])
  
  print(valid_points) # [[1, 3], [1, 4], [2, 3], [2, 4], [3, 3], [3, 4]]
  </code></pre>
  
  <p>This seems a little inefficient for a bigger array as I only need to check a small set of cells really not the whole martix.</p>