Re: Ranks for an array of triplets

*To*: mathgroup at smc.vnet.net*Subject*: [mg87514] Re: [mg87498] Ranks for an array of triplets*From*: Sseziwa Mukasa <mukasa at jeol.com>*Date*: Sat, 12 Apr 2008 06:56:39 -0400 (EDT)*References*: <200804110957.FAA08413@smc.vnet.net>

On Apr 11, 2008, at 5:57 AM, Claus wrote: > I can create an array with x,y,z triplets. x,y are on a regularly > spaced > raster, z is a RandomReal. > For sorting the array according to the z values, I found two options, > the second of which is significantly faster. > However, my goal is not to sort, but to calculate the rank of the z > value within the triplet. > For example: > original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} > convert to: {0,0,2},{0,1,1},{1,1,3} > =E2=86=92 2.3 is the smallest z-value, hence it gets assigned rank 1 > > In my case I can reach this converted array only with extra steps: > - separating the z-values from Ar, > - calculating the (standardized) "RanksOfAr", > - "gluing" the triplets back together. > > Is there a way to to this in one step? You can combine all the steps into one expression but the individual operations still need to be done. You don't need to to pull the array completely apart and put it back together, just join the first two columns of the first array and the rank list then flatten the subelements. FinalAr=Flatten /@ Transpose[{Ar[[All, {1, 2}]], With[{len = Length[Ar]}, N[Ordering[Ar, len, #1[[3]] < #2[[3]] &]/= len]]}] Alternatively if you don't need the original matrix you can destructively assign the ranks back into it. Ar[[All,3]=With[{len = Length[Ar]}, N[Ordering[Ar, len, #1[[3]] < #2= [[3]] &]/len]] Regards, Ssezi

**References**:**Ranks for an array of triplets***From:*Claus <clausenator@gmail.com>