[SciPy-user] Again on Sorting Objects
Johann Cohen-Tanugi
cohen at slac.stanford.edu
Mon Jan 21 15:12:35 EST 2008
great little tools. I realized following this thread that it would be
extremely handy for me to have a fast easy way to do this groupby but on
2D arrays. In other words, starting with
array([[ 1, 12],
[ 1, 24],
[ 2, 3],
[ 2, 60],
[ 2, 100],
[ 3, 75]])
I would love to end with :
array([[ 1, 12],
[ 1, 24]])
array([[ 2, 3],
[ 2, 60],
[ 2, 100]])
array([[ 3, 75]])
or sthg like that. Anyway to do that quickly, based on the previous
mentioned tools?
best,
Johann
Alan G Isaac wrote:
> So ``a`` is already sorted?
> Use groupby?
>
> Cheers,
> Alan Isaac
>
>
>>>> from itertools import groupby
>>>> for t,v in groupby(a): print list(v)
>>>>
> ...
> [2]
> [3]
> [4, 4, 4, 4]
> [5]
> [6, 6]
> [8, 8, 8]
> [10, 10]
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list