MathGroup Archive 2005

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

Search the Archive

Re: Converting a mapping into a well-defined function


Gilmar wrote:

> Dear Carl:
> Your map sorts the set A.
> For example, if A={{47, 53}, {31, 61}, {43, 53}, {43, 47}, {37, 61}};
> then using your f[x_] module, we get f[A]= {{31, 61}, {37, 61}, {43,
> 53}, {47, 53}}, when it should be:
> {{47, 53}, {31, 61}, {43, 53}, {37, 61}}; i.e. an unsorted set.
> Nevertheless I don't mind having your version since it can still come
> handy.

It's a simple matter to modify the code to return an unsorted version:

f[x_]:=Module[{tmp},
 tmp = Transpose[{x[[All,1]],Range[Length[x]],x[[All,2]]}];
 tmp = Split[Sort[tmp], #1[[1]]===#2[[1]]&][[All,1]];
 tmp[[Ordering[tmp[[All,2]]]]][[All,{1,3}]]
 ]

Testing:

A={{47, 53}, {31, 61}, {43, 53}, {43, 47}, {37, 61}};

f[A]
{{47, 53}, {31, 61}, {43, 53}, {37, 61}}

[snip]

Carl Woll



  • Prev by Date: MLGetByteString
  • Next by Date: Re: Floor[] Not An Integer?
  • Previous by thread: Re: Converting a mapping into a well-defined function
  • Next by thread: Re: Converting a mapping into a well-defined function