[SciPy-user] Again on Sorting Objects

Lorenzo Isella lorenzo.isella@gmail....
Mon Jan 21 11:46:42 CST 2008


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).
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 |]

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


More information about the SciPy-user mailing list