MathGroup Archive 2001

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

Search the Archive

RE: Partitioning 1-D list into 2-D Matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29770] RE: [mg29758] Partitioning 1-D list into 2-D Matrix
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 8 Jul 2001 01:00:13 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Chris,

b = Range[20];
b1 = Partition[b, Length[b]/2]
b2 = Transpose[Partition[#, 2]] & /@ b1
Flatten[b2, 1]
{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}}
{{{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}, {{11, 13, 15, 17, 19}, {12, 14, 16,
18,
      20}}}
{{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}, {11, 13, 15, 17, 19}, {12, 14, 16, 18,
    20}}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> From: Krautschik, Chris G [mailto:krautschikc at intel.co.jp]
To: mathgroup at smc.vnet.net
>
> I have a question of how to best select elements from a list and reformat
> the list into a 2D matrix. Here is an example:
>
> b=Range[1,20]
> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
>
> I would like to arrange the list into a 2D array of the following form:
> {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}, {11, 13, 15, 17, 19}, {12, 14, 16, 18,
> 20}}
>
> Then
> bb=Partition[Partition[b,2],5]
>  <<...OLE_Obj...>>
> almost does what I want if you view this array in MatrixForm[]. However, I
> would have to somehow get rid of the innner brackets. I am not sure how to
> do that with Flatten[].
>
> I could use brute force and select the elements as follows:
>  <<...OLE_Obj...>>
>  <<...OLE_Obj...>>
>
> I have a feeling there is a much better way to do this.
>
> Thanks in advance,
> Chris
>
>



  • Prev by Date: Re: Partitioning 1-D list into 2-D Matrix
  • Next by Date: RE: Rotating tick marks
  • Previous by thread: Re: Partitioning 1-D list into 2-D Matrix
  • Next by thread: Re: Partitioning 1-D list into 2-D Matrix