title: Summation of only consecutive values in a python array
body: <p>I am new on python (and even programing!), so I will try to be as clear as I can to explain my question. For you guys it could be easy, but I have not found a satisfactory result on this yet.</p>
  
  <p>Here is the problem:</p>
  
  <p>I have an array with both negative and positive values, say:</p>
  
  <pre><code>x = numpy.array([1, 4, 2, 3, -1, -6, -6, 5, 6, 7, 3, 1, -5, 4, 9, -5, -2, -1, -4])
  </code></pre>
  
  <p>I would like to sum ONLY the <strong>negative</strong> values that are <strong>continuous</strong>, i.e. only <em>sum</em>(-1, -6, -6), <em>sum</em>(-5, -2, -1, -4) and so on. I have tried using <em>numpy.where</em>, as well as <em>numpy.split</em> based on the condition.</p>
  
  <p>For example: </p>
  
  <pre><code> for i in range(len(x)):
       if x[i] &lt; 0.:
           y[i] = sum(x[i])
  </code></pre>
  
  <p>However, as you can expect, I just got the summation of all negative values in the array instead. In this case  <strong>sum</strong>(-1, -6, -6, -5, -5, -2, -1, -4)
  Could guys share with me an aesthetic and efficient way to solve this problem? I will appreciate any response on this.</p>
  
  <p>Thank you very much  </p>