title: Python code for counting number of zero crossings in an array
body: <p>I am looking to count the number of times the values in an array change in polarity (EDIT: Number of times the values in an array cross zero). </p>
  
  <p>Suppose I have an array:</p>
  
  <pre><code>[80.6  120.8  -115.6  -76.1  131.3  105.1  138.4  -81.3
   -95.3  89.2  -154.1  121.4  -85.1  96.8  68.2]`
  </code></pre>
  
  <p>I want the count to be 8. </p>
  
  <p>One solution is to run a loop and check for greater than or less than 0, and keep a history of the previous polarity. </p>
  
  <p>Can we do this faster?</p>
  
  <p>EDIT: My purpose is really to find something faster, because I have these arrays of length around 68554308, and I have to do these calculations on 100+ such arrays. </p>