title: vectorized method to count number of special instances in numpy array
body: <p>Let's say I have an array that is </p>
  
  <p><code>test = np.array([0,2,1,5,3,6,10,0,0,3,2,3,0,0,7,3,6,2,0,0,3,5,4,6])</code></p>
  
  <p>What I want to know is the number of times when the next value is non-zero when the previous value is zero; so for the above array I should have 4.</p>
  
  <p>I wrote a function that does that but it is performing very slow. Is there any vectorized function that I should re-write it into?</p>
  
  <pre><code>def count_instance(array):
      return int(array[0] &gt; 0) + sum(int(array[i] &gt; 0 and array[i-1] == 0) for i in range(1,array.shape[0]))
  </code></pre>