Re: How to sort a 2-d array by the descending order of the other 1-d array?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 30 Apr 2007 13:33:17 -0600 (MDT)

Leo,

I think the best way is to use dim_pqsort to return the permutation
vector from sorting y in decreasing order (but don't actually sort y),
and then use this permutation vector to create a sorted x. Here's an
example:

; m = 5
; n = 2

   x = (/ (/1,2/), (/3,4/), (/5,6/),(/7,8/),(/9,10/) /)
   y = (/8,0,1,-2,4/)

   isort = dim_pqsort(y,-1)
   xsort = x(isort,:)

   print(xsort)

--Mary

On Tue, 1 May 2007, LEO_ARIES wrote:

> Hi, all
>
> I have a 2-d array x(m,n) and a 1-d array y(m), and I want to sort the array of x
> by the descending order of y.
>
> For example, assume x(m,n) = (/ x(0,0),x(0,1), ...x(0,n-1)
> x(1,0),x(1,1), ...x(1,n-1)
> ...
> x(m-1,0),x(m-1,2) ... x(m-1,n-1)/)
> and y(m) = (/y(0),y(1), ...y(m-1)/)
>
> also assume y(1) is the max value of y , then is y(m-1) , and y(0) is the minimun value of y
>
> I want the x(m,n) to be in order like these : x = (/ x(1,0),x(1,1) ,.....
> x(m-1,0),x(m-1,1) , ...
> ....
> x(0,0),x(0,1) , .... x(0,n-1)/)
> How could I get it? Thanks a lot
>
>
>
> Leo
>
>
>
>
> LEO_ARIES
> 2007-05-01
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 30 2007 - 13:33:17 MDT

This archive was generated by hypermail 2.2.0 : Tue May 01 2007 - 08:38:55 MDT