title: Count consecutive occurences of values varying in length in a numpy array
body: <p>Say I have a bunch of numbers in a numpy array and I test them based on a condition returning a boolean array:</p>
  
  <pre><code>np.random.seed(3456)
  a = np.random.rand(8)
  condition = a&gt;0.5
  </code></pre>
  
  <p>And with this boolean array I want to count all of the lengths of consecutive occurences of True. For example if I had <code>[True,True,True,False,False,True,True,False,True]</code> I would want to get back <code>[3,2,1]</code>.</p>
  
  <p>I can do that using this code:</p>
  
  <pre><code>length,count = [],0
  for i in range(len(condition)):
  
      if condition[i]==True:
          count += 1
      elif condition[i]==False and count&gt;0:
          length.append(count)
          count = 0
  
      if i==len(condition)-1 and count&gt;0:
          length.append(count)
  
      print length
  </code></pre>
  
  <p>But is there anything already implemented for this or a python,numpy,scipy, etc. function that counts the length of consecutive occurences in a list or array for a given input?</p>