Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Partition a list based on columns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119665] Re: Partition a list based on columns
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 17 Jun 2011 00:06:31 -0400 (EDT)
  • References: <itcdai$d13$1@smc.vnet.net>

On Jun 16, 1:02 am, StatsMath <stats.ma... at 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]


  • Prev by Date: Re: Mathematica syntax problem: tsntxi
  • Next by Date: Re: Mathematica syntax problem: tsntxi
  • Previous by thread: Re: Partition a list based on columns
  • Next by thread: Re: Partition a list based on columns