[SciPy-user] Again on Sorting Objects

Johann Cohen-Tanugi cohen@slac.stanford....
Mon Jan 21 11:47:34 CST 2008



Lorenzo Isella wrote:
> Dear All,
> Again I am struggling with objects I have to re-arrange.
> Say you have the array (already sorted):
>
> [2 3 4 4 4 4 5 6 6 8 8 8  10 10]
>
> I now would like to find (definitely in a more efficient way than I am
> doing now):
> 1) how many different elements I have in the array (in this case 7:
> 2,3,4,5,6,8,10).
>   
I got an answer about a similar questions yesterday :) : try  
numpy.unique1d(your_array)
> 2)where each block of identical, repeated elements starts and finishes.
> I.e. I would like to break up the array this way:
>
> [2 | 3 | 4 4 4 4 | 5 | 6 6 | 8 8 8 | 10 10 |]
>   
that I don't have the answer straight away....

hth,
J.
> thus getting a list of "right boundaries" of each block of repeated elements.
> I have been playing with sort and argsort, but with no success.
> Many thanks
>
> Lorenzo
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   


More information about the SciPy-user mailing list