Comparing by section two numpy arrays in python
<p>I want to do a comparison between the two arrays by section.
so far I have to get results for all arrays.</p>

<pre><code>import numpy as np
array1 = np.array(list(np.zeros(20))+(list(np.ones(20)))+(list(2*np.ones(20))))
array2 = np.array(list(np.ones(20))+(list(np.ones(20)))+(list(3*np.ones(20))))
result = np.sum(array1 == array2)
print 'all result :' + str(result)
</code></pre>

<p>how to can result in parts, such as the first data 20 then 20 the second data and 20 third data in the array??
the result should be:</p>

<p>all result : 20</p>

<p>result for 20 firt data : 0</p>

<p>result for 20 second data : 20</p>

<p>result for 20 third data : 0</p>

<p>Just sum each 20 separately:</p>

<pre><code>matches = array1 == array2
print 'first  20: {}'.format(matches[:20].sum())
print 'second 20: {}'.format(matches[20:40].sum())
print 'third  20: {}'.format(matches[40:60].sum())
</code></pre>

<p><code>np.sum(x)</code> is usually equivalent to <code>x.sum()</code></p>

python arrays python-2.7 numpy