title: What is an efficient way of counting groups of ones on 2D grid in python? [Figures below]
body: <p>I have a few hundred 2D numpy arrays. They contain zeros and ones. A few examples with plots, yellow indicates ones, purple indicates zeros:</p>
  
  <pre><code>grid1=np.array([[1, 1, 0, 0, 1, 1, 0, 0],
                 [1, 1, 0, 1, 1, 1, 0, 0],
                 [1, 1, 0, 1, 1, 1, 0, 0],
                 [1, 0, 0, 0, 1, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0]])
  
  plt.imshow(grid1)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/apiQo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/apiQo.png" alt="enter image description here"></a></p>
  
  <pre><code>grid2=np.array([[1, 1, 0, 0, 0, 0, 0, 0],
                 [1, 1, 1, 1, 1, 0, 0, 0],
                 [1, 1, 1, 1, 1, 0, 0, 0],
                 [1, 0, 0, 1, 1, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0, 0, 0]])
  
  plt.imshow(grid2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YYX28.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YYX28.png" alt="enter image description here"></a></p>
  
  <pre><code>grid3=np.array([[1, 1, 0, 0, 1, 0, 0, 1],
                 [0, 1, 0, 1, 1, 0, 1, 1],
                 [0, 1, 0, 1, 1, 0, 0, 0],
                 [0, 0, 0, 0, 1, 1, 1, 0],
                 [1, 1, 1, 0, 0, 0, 0, 0]])
  
  plt.imshow(grid3)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7XiJS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7XiJS.png" alt="enter image description here"></a></p>
  
  <p>I'm looking for an efficient way to count the number of yellow blobs on the images. 2, 1 and 4 blobs on the images above, from top to bottom.</p>
  
  <p>Is there an easy way to do this or I have to check each yellow bit to be in the same blob as all the other yellows, and write a script for that? (That looks very painful.)</p>