Is there a way I can "tag" adjacent elements in a numpy array with the same element?
<p>I'm using python 2.7 and I randomly generate areas in OpenCV that at the end look like this in a numpy array:</p>

<pre><code>    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 1 1 0 0
    0 0 0 0 0 0 0 0 0 0 1 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 1 1 1 0 0 0 0 0 0
    0 0 0 0 0 1 1 1 0 0 0 0 0 0
    0 0 0 0 0 1 1 0 0 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
</code></pre>

<p>I actually work with bigger matrices and can generate up to 5 areas. 
What I want to do is to read the generated matrix and "group" areas to generate a second matrix that looks like this:</p>

<pre><code>    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 1 1 0 0
    0 0 0 0 0 0 0 0 0 0 1 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 1 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 2 2 2 0 0 0 0 0 0
    0 0 0 0 0 2 2 2 0 0 0 0 0 0
    0 0 0 0 0 2 2 0 0 0 0 0 0 0
    0 0 0 0 0 2 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0
</code></pre>

<p>So if at the end I have a matrix with 5 numbered spots.
I'm pretty new to python but somehow I think that may be an easy a fast way of doing this. I hope someone can help me.</p>