MathGroup Archive 2004

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

Search the Archive

Re: unpartition


On 29 Jan 2004, at 11:34, Steven Burger wrote:

> How do you unpartition a matrix?
>
> For example: Starting with,
>
> Partition[Table[4*(i - 1) + j, {i, 4}, {j, 4}],{2,2}]
>
>
> how do you go back to,
>
> Table[4*(i - 1) + j, {i, 4}, {j, 4}]
>
>
>
There is no "Unpartition" function (there are just too many possible 
way to unpartition a list) so you vae to compose something yourself. 
Here is one attempt (same example as yours!)


ll=Partition[Range[16],4]


{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12},
  {13, 14, 15, 16}}


Map[Flatten,Flatten[Transpose[ll,{1,3,2}],1]]


{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12},
  {13, 14, 15, 16}}

Another way that comes to my mind is based on the function AppendRows 
form the LinearAlgebra`MatrixManipulation` package:

<< LinearAlgebra`MatrixManipulation`


Flatten[Apply[AppendRows,ll,1],1]

{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12},
  {13, 14, 15, 16}}

There are certainly a vast number of other ways and there may be among 
them a much simpler one.


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: arnoldi method with Mathematica
  • Next by Date: Re: Problem with graphics
  • Previous by thread: unpartition
  • Next by thread: Re: unpartition