Re: Flatten and BlockProcessing
- To: mathgroup at smc.vnet.net
- Subject: [mg65656] Re: [mg65618] Flatten and BlockProcessing
- From: János <janos.lobb at yale.edu>
- Date: Wed, 12 Apr 2006 06:00:06 -0400 (EDT)
- References: <200604110804.EAA11217@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Apr 11, 2006, at 4:04 AM, 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
Here is a newbie approach for the particular case:
In[1]:=
mat = {{{{a, b}, {e, f}},
{{c, d}, {g, h}}},
{{{k, l}, {o, p}},
{{m, n}, {q, r}}}}
Out[1]=
{{{{a, b}, {e, f}},
{{c, d}, {g, h}}},
{{{k, l}, {o, p}},
{{m, n}, {q, r}}}}
In[2]:=
Flatten[
((Join[#1[[1]],
#1[[2]]] & ) /@
Transpose[#1] & ) /@
mat, 1]
Out[2]=
{{a, b, c, d}, {e, f, g, h},
{k, l, m, n}, {o, p, q, r}}
That might help to find a solution for the general case.
János
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)
- References:
- Flatten and BlockProcessing
- From: "Maarten van der Burgt" <maarten.vanderburgt@icos.be>
- Flatten and BlockProcessing