MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Ranks for an array of triplets

  • To: mathgroup at
  • Subject: [mg87514] Re: [mg87498] Ranks for an array of triplets
  • From: Sseziwa Mukasa <mukasa at>
  • Date: Sat, 12 Apr 2008 06:56:39 -0400 (EDT)
  • References: <>

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 

FinalAr=Flatten /@
  Transpose[{Ar[[All, {1, 2}]],
    With[{len = Length[Ar]}, N[Ordering[Ar, len, #1[[3]] < #2[[3]] &]/=


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



  • Prev by Date: Re: Import .xlsx files
  • Next by Date: Re: what does Method->"HighDimensionalEmbedding" actually do for GraphPlot?
  • Previous by thread: Ranks for an array of triplets
  • Next by thread: Re: Ranks for an array of triplets