Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg57597] Re: opposite of partition
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at 9online.fr>
  • Date: Wed, 1 Jun 2005 06:04:36 -0400 (EDT)
  • Organization: New York University
  • References: <d7han9$3r7$1@smc.vnet.net>
  • Reply-to: jmg336 at nyu.edu
  • Sender: owner-wri-mathgroup at wolfram.com

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?
> 
Hi Guy,

I am not sure to have understood exactly what you wanted; however the 
following ideas came up:

In[1]:=
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}}

Out[1]=
{{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}}

In[2]:=
l2 = Partition[l1, {2, 2}]

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

In[3]:=
Flatten /@ l2

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

In[4]:=
Map[Flatten, l2, {2}]

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

Hope this helps,
/J.M.


  • Prev by Date: Re: Two related question. Question 1
  • Next by Date: Re: List searching
  • Previous by thread: Re: opposite of partition
  • Next by thread: Re: opposite of partition