[Date Index]
[Thread Index]
[Author Index]
Re: Ordering function weird?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg82672] Re: Ordering function weird?
*From*: "Christopher J. Henrich" <chenrich at monmouth.com>
*Date*: Sun, 28 Oct 2007 03:59:01 -0500 (EST)
*References*: <ffv29v$aph$1@smc.vnet.net>
In article <ffv29v$aph$1 at smc.vnet.net>, Claus <claus.haslauer at web.de>
wrote:
> 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}
>
Ordering[x] is a permutation - the one which turns x into Sort[x].
Thus, if Sort[x][[i]] came from position j in x, then Ordering[x][[i] =
j.
In your example, y = {1, 2, 7, 8, 9, 1, 2},
Sort[y] = {1, 1, 2, 2, 7, 8, 9}.
Element 1 of Sort[y] came from position 1 in y. Therefore element 1 of
Ordering[y] is 1.
Element 2 of Sort[y] came from position 6 in y. Therefore element 2 of
Ordering[y] is 6.
Iit appears that equal elements in the original list retain their
original order.
Element 3 of Sort[y] came from position 2 in y. Therefore element 3 of
Ordering[y] is 2.
Element 4 of Sort[y] came from position 7 in y. Therefore element 4 of
Ordering[y] is 7.
And so on.
The text in the online documentation is "the position in /list/ at
which each successif element of 'Sort'[/list/] appears." If you
expected to see "the position in 'Sort'[/list/] of each successive
element in /list/", then you would have expected the inverse
permutation to the one that Ordering gave you.
A permutation and its inverse are usually different. I notice that in
your example "x", where Ordering[x] = {1, 2, 3, 6, 7, 4, 5}, this
permutation is its own inverse. (The odds against this were 47:1.)
--
Chris Henrich
http://www.mathinteract.com
God just doesn't fit inside a single religion.
Prev by Date:
**Solving Inequality**
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?**
| |