Re: Sorting point-arrays by rows and columns, cont.

• To: mathgroup at smc.vnet.net
• Subject: [mg124081] Re: Sorting point-arrays by rows and columns, cont.
• From: Chris Young <cy56 at comcast.net>
• Date: Sun, 8 Jan 2012 04:24:51 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <je6e3j\$q6k\$1@smc.vnet.net> <je96m6\$j6c\$1@smc.vnet.net>

```Despite what I said, it seems to be working now. Fold[ ] looks useful
for more complicated sorting especially.

In[75]:= FoldList[
#1[[Ordering[#1[[All, #2]], All, LessEqual]]] &,
hexPts,
{1, 2}
]
The first list below is hexPts unaltered.
The second is hexPts sorted by the x coordinates, i.e., by columns.
The third is hexPts sorted by the y coordinates, but with the
x-coordinates ordered within each row.

Out[75]=
{
{{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/2}, {-1, 0},
{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}},
{{-1, 0}, {-(1/2), Sqrt[3]/2}, {-(1/2), -(Sqrt[3]/2)}, {0, 0}, {1/2,
Sqrt[3]/2}, {1/2, -(Sqrt[3]/2)}, {1, 0}},
{{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1, 0}, {0, 0}, {1, 0},
{-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}
}

On 2012-01-07 10:27:18 +0000, Chris Young said:

> Thanks for the examples with Fold, which I'm going to continue to work
> through, but I wasn't able to get it to sort the 2nd elements correctly:
>
> In[10]:= threes = RandomChoice[Flatten[pts], {10, 3}]
>
> Out[10]= {{1, 2, 0}, {1, Sqrt[2], 1}, {1, 7, 2}, {1, 1, Sqrt[5]}, {1,
> 2,  2}, {0, 4, -1}, {0, 2, 1}, {7, 1, 0}, {1, Sqrt[5], 2}, {0, 2, -1}}
>
>
> (The following doesn't seem to work!! We have Sqrt[5] in the 2nd
> coordinate coming before 1 in the last two vectors.
> Don't understand why Reverse was needed, and also why {3,1} was used.
> What does the {3,1} to?)
>
> In[35]:= Fold[#1[[Ordering[#1[[All, #2]], All, LessEqual]]] &, threes,
>  Reverse@{3, 1}]
>
> Out[35]= {{0, 4, -1}, {0, 2, -1}, {1, 2, 0}, {7, 1, 0}, {0, 2, 1}, {1,
> Sqrt[2], 1}, {1, 7, 2}, {1, 2, 2}, {1, Sqrt[5], 2}, {1, 1, Sqrt[5]}}

```

• Prev by Date: Re: ParametricPlot3D vs Reduce
• Next by Date: Re: MatrixPower problem
• Previous by thread: Re: Sorting point-arrays by rows and columns, cont.
• Next by thread: Re: Sorting point-arrays by rows and columns, cont.