MathGroup Archive 2007

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

Search the Archive

Re: Ordering function weird?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82691] Re: Ordering function weird?
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sun, 28 Oct 2007 04:08:58 -0500 (EST)
  • References: <ffv29v$aph$1@smc.vnet.net>

Claus,

Read the Help for Ordering carefully.

y = {1, 2, 7, 8, 9, 1, 2}
Sort[y]
Ordering[y]

The identity between Ordering and Sort is as follows:

Part[y, Ordering[y]] == Sort[y]

This spells it out in more detail:

Column@MapThread[
  Row[{"Element number ", #1, " \[Equal] ", #2,
     " in Sort[y] is in position ", #3, " \[Equal] ", Part[y, #3],
     " in y"}] &, {Range[Length[y]], Sort[y], Ordering[y]}]

The advantage of Ordering is that you could now reorder another equal length 
list, say the x list, in the same way that Sort[y] reordered the y list.

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


"Claus" <claus.haslauer at web.de> wrote in message 
news:ffv29v$aph$1 at smc.vnet.net...
> Hi,
> say I've got two sets of number, x and y, which I want to rank. See the
> example below. I totally expect and want the result of Ordering[x]. But
> I neiter understand nor expect the result of Ordering[y]. Both Sort[x]
> and Sort[y] are ok.
> Can anybody explain to me Ordering[y]?
> Thanks,
> Claus
>
>
> In[3]:= x = {1, 2, 3, 6, 10, 3, 4}
> y = {1, 2, 7, 8, 9, 1, 2}
>
> Out[3]= {1, 2, 3, 6, 10, 3, 4}
>
> Out[4]= {1, 2, 7, 8, 9, 1, 2}
>
> In[5]:= Sort[x]
> Sort[y]
>
> Out[5]= {1, 2, 3, 3, 4, 6, 10}
>
> Out[6]= {1, 1, 2, 2, 7, 8, 9}
>
> In[7]:= Ordering[x]
> Ordering[y]
>
> Out[7]= {1, 2, 3, 6, 7, 4, 5}
>
> Out[8]= {1, 6, 2, 7, 3, 4, 5}
> 



  • Prev by Date: Re: Ordering function weird?
  • Next by Date: Re: Can't calculate numerical derivative of EllipticTheta
  • Previous by thread: Re: Ordering function weird?
  • Next by thread: Re: Ordering function weird?