Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5551
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Sort on vector component |
| Date | 2011-10-09 08:00 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j6rkb3$1pt$1@smc.vnet.net> (permalink) |
| References | <201110080936.FAA21131@smc.vnet.net> |
u = {{2, 12, 7, 21}, {2, 48, 47, 97}, {4, 42, 41, 87}, {6, 8, 1,
15}, {6, 12, 9, 27}};
n = RandomChoice@Range@Last@Dimensions@u
3
SortBy[u, #[[n]] &]
{{6, 8, 1, 15}, {2, 12, 7, 21}, {6, 12, 9, 27}, {4, 42, 41, 87}, {2,
48, 47, 97}}
u[[Ordering@u[[All, n]]]]
{{6, 8, 1, 15}, {2, 12, 7, 21}, {6, 12, 9, 27}, {4, 42, 41, 87}, {2,
48, 47, 97}}
Bobby
On Sat, 08 Oct 2011 04:36:18 -0500, Dr. Wolfgang Hintze <weh@snafu.de>
wrote:
> Given a list
>
> u = {{2, 12, 7, 21}, {2, 48, 47, 97}, {4, 42, 41, 87},
> {6, 8, 1, 15}, {6, 12, 9, 27}}
>
> How can I sort it with respect to a given index position i=(1, ..., 4)?
>
> For i=1 it is simply Sort, for the last one I could use
>
> In[75]:=
> Reverse /@ Sort[Reverse /@ u]
> Out[75]=
> {{6, 8, 1, 15}, {2, 12, 7, 21}, {6, 12, 9, 27},
> {4, 42, 41, 87}, {2, 48, 47, 97}}
>
> I don't want to go in the details of defining lexicographical order but
> just obtain a sorting as described above.
>
> Any ideas?
>
> Thanks in advance.
>
> Wolfgang
>
>
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Sort on vector component DrMajorBob <btreat1@austin.rr.com> - 2011-10-09 08:00 +0000
csiph-web