Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3164
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Partition a list based on columns |
| Date | 2011-06-17 09:52 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <itf859$239$1@smc.vnet.net> (permalink) |
| References | <itcdai$d13$1@smc.vnet.net> <201106170406.AAA28684@smc.vnet.net> |
How about
Clear[m, n]
m[x_List] := Module[{n = Sqrt@Length@x},
Normal@SparseArray[
Rule @@@
Transpose@{SortBy[Flatten[Array[List, {n, n}], 1], Total], x}] /;
IntegerQ@n
]
m[Range@9] // MatrixForm
(* suppressed *)
m[Range@16] // MatrixForm
(* suppressed *)
m[Range@7]
m[{1, 2, 3, 4, 5, 6, 7}]
Bobby
On Thu, 16 Jun 2011 23:06:31 -0500, Ray Koopman <koopman@sfu.ca> wrote:
> On Jun 16, 1:02 am, StatsMath <stats.ma...@gmail.com> wrote:
>> [...]
>>
>> What would be a good way to line up elements in a list in a diagonal
>> fashion, for ex: from Range[9] want to create the follwing matrix:
>>
>> 1 2 4
>> 3 5 7
>> 6 8 9
>
> This is better than my previous suggestion:
>
> m[n_] := Partition[FoldList[Plus,0,Join[Range[n-1],Range[n-1,1,-1]]],
> n, 1] + Range[n]
>
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Partition a list based on columns StatsMath <stats.math8@gmail.com> - 2011-06-16 08:02 +0000 Re: Partition a list based on columns Ray Koopman <koopman@sfu.ca> - 2011-06-16 10:24 +0000 Re: Partition a list based on columns Ray Koopman <koopman@sfu.ca> - 2011-06-17 04:09 +0000 Re: Partition a list based on columns Ray Koopman <koopman@sfu.ca> - 2011-06-17 04:06 +0000 Re: Partition a list based on columns DrMajorBob <btreat1@austin.rr.com> - 2011-06-17 09:52 +0000
csiph-web