title: Function to get top left and bottom right indexes of nonzero elements in an array
body: <p>So the goal is to write a function that gives the top left and bottom right indexes of a group of nonzero elements of an array. Two groups cant be next to eachother in the array. And if the group exist of just one element, the top left and bottom right indexes are the same. It was easy to get a function that gets all the indexes of nonzero elements, but I cant seem to filter it so just the top left and bottom right indexes remain.
  Here is the function I already got:</p>
  <pre><code>import numpy as np
  def get_indexes(A):
      M,N = A.shape
      pos = []
      for i in range(M):
          for j in range(N):
              if A[i,j]!=0:
                  pos.append((i,j,A[i,j]))
      return pos
  
  </code></pre>
  <p>And here is an example of a given array:</p>
  <pre><code>A= np.array([[0, 7, 7, 0, 0, 0, 0, 0, 0],
  [0, 7, 7, 0, 0, 9, 0, 0, 0],
  [0, 7, 7, 0, 0, 9, 0, 0, 0],
  [0, 7, 7, 0, 0, 9, 0, 0, 0],
  [0, 7, 7, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 1, 0, 0],
  [6, 6, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 5, 5, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0]])
  </code></pre>
  <p>I appreciate the help!</p>