MathGroup Archive 2012

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

Search the Archive

Sorting point-arrays by rows and columns, cont.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124022] Sorting point-arrays by rows and columns, cont.
  • From: Chris Young <cy56 at comcast.net>
  • Date: Fri, 6 Jan 2012 04:14:37 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

I don't see why what I'm doing below doesn't sort into rows and columns.



>From the Help on SortBy:
\!\(\*
ButtonBox["SortBy",
BaseStyle->"Link",
ButtonData->"paclet:ref/SortBy"]\)[e, f] is equivalent to \!\(\*
ButtonBox["Sort",
BaseStyle->"Link",
ButtonData->"paclet:ref/Sort"]\)[{f[#], #} & /@ e][[\!\(\*
ButtonBox["All",
BaseStyle->"Link",
ButtonData->"paclet:ref/All"]\), -1]]:
In[1098]:= e = RandomInteger[9, {10, 2}]
Out[1098]= {{3, 6}, {4, 6}, {6, 0}, {8, 7}, {1, 3}, {7, 4}, {8, 6}, {0, 
3}, {3, 0}, {4, 5}}
In[1099]:= SortBy[e, Last]
Out[1099]= {{3, 0}, {6, 0}, {0, 3}, {1, 3}, {7, 4}, {4, 5}, {3, 6}, {4, 
6}, {8, 6}, {8, 7}}
In[1101]:= {Last[#], #} & /@ e
Out[1101]= {{6, {3, 6}}, {6, {4, 6}}, {0, {6, 0}}, {7, {8, 7}}, {3, {1, 
3}}, {4, {7, 4}}, {6, {8, 6}}, {3, {0, 3}}, {0, {3, 0}}, {5, {4, 5}}}
In[1105]:= Sort[{Last[#], #} & /@ e]
Out[1105]= {{0, {3, 0}}, {0, {6, 0}}, {3, {0, 3}}, {3, {1, 3}}, {4, {7, 
4}}, {5, {4, 5}}, {6, {3, 6}}, {6, {4, 6}}, {6, {8, 6}}, {7, {8, 7}}}
In[1104]:= Sort[{Last[#], #} & /@ e]  [[1, -1]]
Out[1104]= {3, 0}
Sort[{Last[#], #} & /@ e]  [[All, -1]]
Out[1100]= {{3, 0}, {6, 0}, {0, 3}, {1, 3}, {7, 4}, {4, 5}, {3, 6}, {4, 
6}, {8, 6}, {8, 7}}
Trying to apply this to hexagonal point array:
In[1108]:= hex
Out[1108]= {{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)}}
In[1109]:= {Part[#, 2], Part[#, 1], #} & /@ hex
Out[1109]= {{0, 0, {0, 0}}, {0, 1, {1, 0}}, {Sqrt[3]/2, 1/2, {1/2, 
Sqrt[3]/2}}, {Sqrt[3]/2, -(1/2), {-(1/2), Sqrt[3]/2}}, {0, -1, {-1, 
0}}, {-(Sqrt[3]/2), -(1/2), {-(1/2), -(Sqrt[3]/2)}}, {-(Sqrt[3]/2), 
1/2, {1/2, -(Sqrt[3]/2)}}}
In[1110]:= Sort[%1109]
Out[1110]= {{0, -1, {-1, 0}}, {0, 0, {0, 0}}, {0, 1, {1, 0}}, 
{-(Sqrt[3]/2), -(1/2), {-(1/2), -(Sqrt[3]/2)}}, {-(Sqrt[3]/2), 1/2, 
{1/2, -(Sqrt[3]/2)}}, {Sqrt[3]/2, -(1/2), {-(1/2), Sqrt[3]/2}}, 
{Sqrt[3]/2, 1/2, {1/2, Sqrt[3]/2}}}




  • Prev by Date: Sorting coefficients
  • Next by Date: Re: Rule replacement doesn't work after NDSolve?
  • Previous by thread: Re: Sorting coefficients
  • Next by thread: Re: Sorting point-arrays by rows and columns, cont.