Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3130

Re: Partition a list based on columns

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Partition a list based on columns
Date 2011-06-16 10:24 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <itclkg$gtq$1@smc.vnet.net> (permalink)
References <itcdai$d13$1@smc.vnet.net>

Show all headers | View raw


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 will give a square matrix of order n whose elements are
the integers 1...n^2 in the positions you asked for:

m[n_] := With[{b=FoldList[Plus,0,Join[Range[n-1],Range[n-1,1,-1]]]},
              Table[Take[b,{i,i+n-1}]+i,{i,n}]]
m[5]

{{ 1,  2,  4,  7, 11},
 { 3,  5,  8, 12, 16},
 { 6,  9, 13, 17, 20},
 {10, 14, 18, 21, 23},
 {15, 19, 22, 24, 25}}

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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