title: How to repeat a numPy array value
body: <p>I was wondering if there was a vertorized way to use two arrays and based on the value of one continuously copy the value in a second array until a new value in the first array is found and then repeat the whole process. </p>
  
  <p>here is an example</p>
  
  <pre><code>   a = np.array([FALSE,TRUE,FALSE,FALSE, FALSE, TRUE, FALSE  FALSE})
     b = np.array([0,10,0,0,0,20,0,0,])
     output = array([0,10,10,10,10,20,20,20])
  </code></pre>
  
  <p>I can use a loop which is much too slow for this.</p>
  
  <pre><code>for i in range(len(b)):   
     if b[i-1] and not b[i]:
         b[i] = b[i-1]
  </code></pre>
  
  <p>Updated:</p>
  
  <p>I tried this code below and increased the speed by 5x but I figure there should be a faster more elegant way of doing this. </p>
  
  <pre><code>import numpy as np
  
  nz= np.concatenate((np.nonzero(b)[0], [len(b)]))
  np.repeat(b[np.nonzero(b)], np.diff(nz))
  </code></pre>