Comparing by section two numpy arrays in python and displays the index column which is not the same
<p>I want to show you where the index column of the array is not the same.</p>

<pre><code>import numpy as np
array1 = np.array(list(np.zeros(10))+list(np.ones(10)))
array2 = np.array(list(np.random.randint(2, size=10))+list(np.random.randint(2, size=10)))
matches = array1 == array2
section_sums = np.bincount(np.arange(matches.size)//10,matches)
att = int(section_sums[0])
att2 = int(section_sums[1])

print section_sums
print 'first  10 : '+ str(att)
print 'second 10 : '+ str(att2)
</code></pre>

<p>example:</p>

<pre><code>Array1:
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  1.  1.  1.  1.  1.  1. 1. 1.]

Array2:
[ 0.  1.  0 . 1.  1.  1.  0.  1.  0.  1.  1.  1.  1.  0.  1.  0.  1.  1. 1. 0.]
</code></pre>

<p>I want the output:</p>

<pre><code>in section 1 index is not the same: 2,4,5,6,8,10
in section 2 index is not the same: 4,6,10
</code></pre>

<p>Here's an approach -</p>

<pre><code>idx = np.flatnonzero(~matches)
cut_idx = np.unique(idx//10,return_index=True)[1]
out = np.split(np.mod(idx,10)+1,cut_idx)[1:]
</code></pre>

<p>Sample run for the given input arrays -</p>

<pre><code>In [182]: matches = array1 == array2
     ...: idx = np.flatnonzero(~matches)
     ...: cut_idx = np.unique(idx//10,return_index=True)[1]
     ...: out = np.split(np.mod(idx,10)+1,cut_idx)[1:]
     ...: 

In [183]: out
Out[183]: [array([ 2,  4,  5,  6,  8, 10]), array([ 4,  6, 10])]
</code></pre>

python arrays python-2.7 numpy