Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: opposite of partition

  • To: mathgroup at
  • Subject: [mg57568] Re: [mg57539] opposite of partition
  • From: Selwyn Hollis <sh2.7183 at>
  • Date: Wed, 1 Jun 2005 06:02:21 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On May 31, 2005, at 5:00 AM, Guy Israeli wrote:

> Hi,
> How do I do the opposite of partition quickly?
> for example:
> l1= {{a, b, c, d, e}, {f, g, h, i, j}, {k, l, m, n, o}, {p, q, r,  
> s, t}, {u,
> v, w,
> x, y}}
> and then if I partition it to blocks will result in
> {{{{a, b}, {f, g}}, {{c, d}, {h, i}}}, {{{k, l}, {p, q}}, {{m, n},  
> {r, s}}}}
> flattening it won't help, and its messy to do it by taking all  
> first lines
> of the blocks, then second..
> How can I do it quickly?
> Thanks,
> Guy


This seems to do what you want:

   revPartition[m_] := Flatten[ Map[ Map[Flatten, #] &, Map 
[Transpose, m] ], 1]

or, if you prefer,

   revPartition[m_] := Flatten[#, 1] &@(Flatten /@ # &) /@ Transpose / 
@ m

Then, e.g.,

   revPartition[{{{{a, b}, {f, g}}, {{c, d}, {h, i}}}, {{{k, l}, {p,  
q}}, {{m, n}, {r, s}}}}]

   --->   {{{a, b, c, d}, {f, g, h, i}}, {{k, l, m, n}, {p, q, r, s}}}

Selwyn Hollis

  • Prev by Date: Re: Block vs Module
  • Next by Date: Re: reducing the time of constructing a List
  • Previous by thread: Re: opposite of partition
  • Next by thread: Re: opposite of partition