|
Re: sorting array column/rowwise [message #31322 is a reply to message #31321] |
Thu, 04 July 2002 06:42  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Marc Schellens (m_schellens@hotmail.com) writes:
> but I wanted to sort each column individually.
> Any guesses?
Here is how I would sort a column of an array.
But I think I would use the BSORT routine,
rather than the SORT routine if I was putting
it into a piece of code that mattered to me.
IDL> a=randomu(-3L, 3, 10)
IDL> print, a
0.897916 0.558249 0.766930
0.589101 0.0603181 0.973112
0.0378892 0.218058 0.142394
0.984703 0.894904 0.947651
0.804079 0.160385 0.208246
0.818130 0.103716 0.741117
0.0134482 0.0960160 0.692969
0.0230946 0.181693 0.0777949
0.269231 0.286594 0.730963
0.727624 0.272199 0.481930
IDL> s1 = sort(a[1,*])
IDL> a[1,*] = (a[1,*])[s1]
IDL> print, a
0.897916 0.0603181 0.766930
0.589101 0.0960160 0.973112
0.0378892 0.103716 0.142394
0.984703 0.160385 0.947651
0.804079 0.181693 0.208246
0.818130 0.218058 0.741117
0.0134482 0.272199 0.692969
0.0230946 0.286594 0.0777949
0.269231 0.558249 0.730963
0.727624 0.894904 0.481930
I expect that if I spent five more minutes on this
I could probably write a generalized program
that would sort on any column. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: sorting array column/rowwise [message #31323 is a reply to message #31322] |
Thu, 04 July 2002 02:26  |
Jaco van Gorkom
Messages: 97 Registered: November 2000
|
Member |
|
|
"Marc Schellens" <m_schellens@hotmail.com> wrote in message news:3D23FB20.5020804@hotmail.com...
...
> but I wanted to sort each column individually.
> Any guesses?
for sorting rows:
If the range of values in each row is limited, then it
might be possible to add an offset to each row that makes
the value ranges of the rows non-overlapping and incrementing.
Then a single call to SORT will provide the correct sorted
indices for the entire array.
for sorting columns:
First do a TRANSPOSE, then sort the rows?
|
|
|
Re: sorting array column/rowwise [message #31324 is a reply to message #31323] |
Thu, 04 July 2002 00:37  |
marc schellens[1]
Messages: 183 Registered: January 2000
|
Senior Member |
|
|
Paul Sorenson wrote:
> Have you looked at the SORT routine? The following example sorts by the
> first column of a.
>
> IDL> a = randomu(seed, 4, 4)
> IDL> print, a[*, sort(a[0, *])]
> 0.303753 0.933435 0.723623 0.636985
> 0.535081 0.804346 0.313356 0.620587
> 0.574060 0.790996 0.821293 0.671731
> 0.799868 0.0666149 0.123060 0.281230
Thanks Paul,
but I wanted to sort each column individually.
Any guesses?
marc
|
|
|
Re: sorting array column/rowwise [message #31326 is a reply to message #31324] |
Wed, 03 July 2002 15:27  |
Paul Sorenson
Messages: 48 Registered: May 2002
|
Member |
|
|
Have you looked at the SORT routine? The following example sorts by the
first column of a.
IDL> a = randomu(seed, 4, 4)
IDL> print, a[*, sort(a[0, *])]
0.303753 0.933435 0.723623 0.636985
0.535081 0.804346 0.313356 0.620587
0.574060 0.790996 0.821293 0.671731
0.799868 0.0666149 0.123060 0.281230
There's also a routine called BSORT at
http://idlastro.gsfc.nasa.gov/ftp/pro/misc/bsort.pro . It is like the IDL
SORT function but subscript order is maintained when values are equal.
-Paul Sorenson
"Marc Schellens" <m_schellens@hotmail.com> wrote in message
news:3D2295BC.5030207@hotmail.com...
> Is there an elegant (ie. without loops) way to sort
> the columns or rows of an array?
> I need the sorted indices.
> thanks,
> marc
>
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
|
|
|