 
 
 
 
 
 
Re: Flatten and BlockProcessing
- To: mathgroup at smc.vnet.net
- Subject: [mg65654] Re: Flatten and BlockProcessing
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 12 Apr 2006 06:00:03 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <e1fp4f$beo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Maarten van der Burgt wrote:
> Hallo,
> 
> I have a structure M:
> 
> M = {{{{a, b}, {e, f}}, {{c, d}, {g, h}}}, {{{k, l}, {o, p}}, {{m, n}, {q,
> r}}}}
> 
> 
> M//Dimensions
> 
> gives
> 
> {2, 2, 2, 2},
> 
> (or more general {n1, n2, m1, m2}; M is the result of the BlockProcessing
> function from the Image Processing package)
> 
> Does anyone know an elegant way of 'flattening' M to give
> 
> {{a, b, c, d}, {e, f, g, h}, {k, l, m, n}, {o, p, q, r}}
> 
> with dimensions {4, 4} (or more general {n1*m1, n2*m2})?
> 
> 
> Thanks for your help,
> 
> 
> Maarten
> 
Hi Marteen,
Something along the following lines might help:
In[1]:=
M = {{{{a, b}, {e, f}}, {{c, d}, {g, h}}},
     {{{k, l}, {o, p}}, {{m, n}, {q, r}}}};
In[2]:=
Partition[Flatten[Partition[Flatten[M], 2, 4]], 4]
Out[2]=
{{a, b, c, d}, {k, l, m, n}}
In[3]:=
Partition[Flatten[Partition[Drop[Flatten[M], 2], 2,
     4]], 4]
Out[3]=
{{e, f, g, h}, {o, p, q, r}}
In[4]:=
Union[%%, %]
Out[4]=
{{a, b, c, d}, {e, f, g, h}, {k, l, m, n},
   {o, p, q, r}}
Regards,
Jean-Marc

