title: calculating streaks using numpy
body: <p>I am trying to calculate positive and negative and no streaks using numpy exclusively.  The issue i'm having to figuring out the groupby component of the equation which all my research has lead to believe I need.  I found a pandas response here <a href="https://stackoverflow.com/questions/42397647/pythonic-way-to-calculate-streaks-in-pandas-dataframe">Pythonic way to calculate streaks in pandas dataframe</a></p>
  
  <p>I've been able to convert all but the groupby piece.  Any help is appreciated</p>
  
  <p>here is the pandas code i would like to reproduce. The only non numpy equivalent is groupby.  I also created my own shift function in numpy. </p>
  
  <p>Pandas version:</p>
  
  <pre><code>def streaks(df, col):
      sign = np.sign(df[col])
      s = sign.groupby((sign!=sign.shift()).cumsum()).cumsum()
      return df.assign(u_streak=s.where(s&gt;0, 0.0), 
      d_streak=s.where(s&lt;0,0.0).abs())
  </code></pre>
  
  <p>My partial numpy version:</p>
  
  <pre><code>arr = np.array([0.2,0.1,0.1,0.0,-0.2,-0.1,0.0])
  sign = np.sign(arr)
  s = np.not_equal(sign, shift(sign))
  # now I need to groupby and then sum and sum again 
  np.cumsum(groupby(np.cumsum(s)))
  </code></pre>
  
  <p>The expected result should be: </p>
  
  <pre><code>array([1.,2.,3.,0.,-1.,-2.,0.])
  </code></pre>