MathGroup Archive 2007

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

Search the Archive

Re: ordered positions (OrderedPosition?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83428] Re: [mg83397] ordered positions (OrderedPosition?)
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Tue, 20 Nov 2007 03:51:26 -0500 (EST)
  • References: <33283927.1195506571006.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

One of these, perhaps:

lists = {{4, 3, 3, 5, 1, 2, 5, 2, 3, 2}, {1, 5, 4, 1, 3, 4, 1, 7, 3,
     4}};

Flatten[MapIndexed[#2 &, lists, {2}], 1][[Ordering@Flatten@lists]]

{{1, 5}, {2, 1}, {2, 4}, {2, 7}, {1, 6}, {1, 8}, {1, 10}, {1, 2}, {1,
   3}, {1, 9}, {2, 5}, {2, 9}, {1, 1}, {2, 3}, {2, 6}, {2, 10}, {1,
   4}, {1, 7}, {2, 2}, {2, 8}}

Position[lists, _Integer][[Ordering@Flatten@lists]]

{{1, 5}, {2, 1}, {2, 4}, {2, 7}, {1, 6}, {1, 8}, {1, 10}, {1, 2}, {1,
   3}, {1, 9}, {2, 5}, {2, 9}, {1, 1}, {2, 3}, {2, 6}, {2, 10}, {1,
   4}, {1, 7}, {2, 2}, {2, 8}}

Bobby

On Mon, 19 Nov 2007 05:18:08 -0600, Christian Chong-White  =

<christian_chongwhite at hotmail.com> wrote:

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



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: MapThread over ragged arrays
  • Next by Date: Neural networks with mathematica
  • Previous by thread: Re: ordered positions (OrderedPosition?)
  • Next by thread: Re: ordered positions (OrderedPosition?)