<HTML><BODY>Hi Todd,<br>Greaaat thanks for your help.. By the way, the first one (I think) is much simpler.. I tested it and ,of course, it is 1D, but it is also a good idea to consider it for Ndimensional.<br>I prefer the first one! Do you you think first version is okay to use? <br><br><br>Среда, 17 апреля 2013, 11:02 +02:00 от Todd <toddrjen@gmail.com>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;" class="mailru-blockquote">
        <div id="">
        



    






        

        
        
        
        
        

        



<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div id="style_13661893890000000957" class="mr_read__body">
                <base target="_self" href="https://e.mail.ru/cgi-bin/">
                
                        <div id="style_13661893890000000957_BODY"><div dir="ltr"><div><div>On Wed, Apr 17, 2013 at 10:46 AM, Todd <span dir="ltr"><<a href="sentmsg?mailto=mailto%3atoddrjen@gmail.com" target="_blank">toddrjen@gmail.com</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div dir="ltr"><div><div>x,i=numpy.unique(y, return_inverse=True)<br></div></div>f=[numpy.where(i==ind) for ind in range(len(x))]<br><div><div><div><br></div><br></div></div></div></blockquote></div><br><br></div><div>

A better version would be (np.where returns tuples, but we don't want tuples):<br><br>x,i=numpy.unique(y, return_inverse=True)<br>f=[numpy.where(i==ind)[0] for ind in range(len(x))]<br><br>You can also do it this way, but it is much harder to read IMO:<br>

<br>x=numpy.unique(y)<br>f=numpy.split(numpy.argsort(y), numpy.nonzero(numpy.diff(numpy.sort(y)))[0]+1)<br><br></div><div>This version figures out the indexes needed to put the values of y in sorted order (the same order x uses), then splits it into sub-arrays based on value.  The principle is simpler but the implementation looks like clear to me.<br>

<br></div><div>Note that these are only guaranteed to work on 1D arrays, I have not tested them on multidimensional arrays<br></div><div><br></div></div>

</div>
                        <div>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="sentmsg?compose&To=NumPy%2dDiscussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br>
</div>
                
                <base target="_self" href="https://e.mail.ru/cgi-bin/">
        </div>

        
</div>


</div>
</blockquote>
<br></BODY></HTML>