Find all occurences of a specified match of two numbers in numpy array
<p>what i need to achieve is to get array of all indexes, where in my data array filled with zeros and ones is step from zero to one. I need very quick solution, because i have to work with milions of arrays of hundrets milions length. It will be running in computing centre. For instance..</p>

<pre><code>data_array = np.array([1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,0])
result = [3,9,13]
</code></pre>

<p>try this:</p>

<pre><code>In [23]: np.where(np.diff(a)==1)[0] + 1
Out[23]: array([ 3,  9, 13], dtype=int64)
</code></pre>

<p>Timing for 100M element array:</p>

<pre><code>In [46]: a = np.random.choice([0,1], 10**8)

In [47]: %timeit np.nonzero((a[1:] - a[:-1]) == 1)[0] + 1
1 loop, best of 3: 1.46 s per loop

In [48]: %timeit np.where(np.diff(a)==1)[0] + 1
1 loop, best of 3: 1.64 s per loop
</code></pre>

python arrays performance numpy