title: How to find all neighbour values near the edge in array?
body: <p>I have an array consisting of <code>0</code>s and <code>1</code>s.
  Firstly, I need to find all neighbour <code>1</code>. I managed to do this (the solution is in the link below).</p>
  
  <p>Secondly, I need to choose those, where any element of cluster located near the top boundary.</p>
  
  <p>I can find neighbours with code from <a href="https://datascience.stackexchange.com/questions/33766/how-to-compare-fast-the-value-with-the-ones-of-neighbours-in-a-3d-array">here</a>.</p>
  
  <p>But I need to select only those that are in contact with the top boundary.</p>
  
  <p>Here is an example with a 2D array:</p>
  
  <p><b>Input:</b></p>
  
  <pre><code>array([[0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
         [0, 0, 0, 1, 1, 0, 0, 0, 1, 0],
         [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
         [1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
         [1, 0, 0, 0, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
         [0, 1, 0, 0, 0, 0, 0, 1, 1, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]])
  </code></pre>
  
  <p><b>Output: </b></p>
  
  <pre><code>array([[0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
         [0, 0, 0, 1, 1, 0, 0, 0, 1, 0],
         [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
  </code></pre>