title: Consecutive elements in a Sparse matrix row
body: <p>I am working on a sparse matrix stored in COO format. What would be the fastest way to get the number of consecutive elements per each row.</p>
  
  <p>For example consider the following matrix:</p>
  
  <pre><code>a = [[0,1,2,0],[1,0,0,2],[0,0,0,0],[1,0,1,0]]
  </code></pre>
  
  <p>Its COO representation would be </p>
  
  <pre><code>  (0, 1)    1
    (0, 2)    2
    (1, 0)    1
    (1, 3)    2
    (3, 0)    1
    (3, 2)    1
  </code></pre>
  
  <p>I need the result to be <code>[1,2,0,2]</code>. The first row contains two Non-zero elements that lies nearby. Hence its a group or set. In the second row we have two non-zero elements,but they dont lie nearby, and hence we can say that it forms two groups. The third row there are no non-zeroes and hence no groups. The fourth row has again two non-zeroes but separated by zeroes nad hence we consider as two groups. It would be like the number of clusters per row. Iterating through the rows are an option but only if there is no faster solution. Any help in this regard is appreciated. </p>
  
  <p>Another simple example: consider the following row:</p>
  
  <pre><code>[1,2,3,0,0,0,2,0,0,8,7,6,0,0]
  </code></pre>
  
  <p>The above row should return <code>[3]</code> sine there are three groups of non-zeroes getting separated by zeroes.</p>