MathGroup Archive 2007

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

Search the Archive

ordered positions (OrderedPosition?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83397] ordered positions (OrderedPosition?)
  • From: Christian Chong-White <christian_chongwhite at hotmail.com>
  • Date: Mon, 19 Nov 2007 06:18:08 -0500 (EST)

Hi Folks

I am wanting an elegant solution to find an ordering of elements of a
set of nested lists at a specific level (the base level in this case
but need not be). The output I am after is an ordered set of positions
that references each of those elements in the original structure.

To explain: My ugly work-around was to flatten the nested list to get
the ordering but this loses the structural information.

In[22]:= Ordering[
 Flatten@{{4, 3, 3, 5, 1, 2, 5, 2, 3, 2}, {1, 5, 4, 1, 3, 4, 1, 7, 3,
4}}]

Out[22]= {5, 11, 14, 17, 6, 8, 10, 2, 3, 9, 15, 19, 1, 13, 16, 20, 4,
7, 12, 18}

The problem with the above is I have lost the information where in the
structure the element was. I need the functionality of Position -
including reference to depth, and Ordering.

Taking the above example further, what I am after is something like:
{{1,5},{2,1}, etc}
representing sorted positions of the original structure rather than
{5,11, etc} of the flattened list.

It seems a very "Mathematica thing" I am after, and something that
could well fit within an enhanced version of Ordering, but am lost at
how to address the problem in a "Mathematica elegant manner."

Cheers
Christian


  • Prev by Date: Re: What is a good way of returning a function from a Module[]?
  • Next by Date: SeriesCoefficient: needs work!
  • Previous by thread: Re: Plotting Points with Labels
  • Next by thread: Re: ordered positions (OrderedPosition?)