       Re: How to unflatten an array ?

• To: mathgroup at smc.vnet.net
• Subject: [mg112845] Re: How to unflatten an array ?
• From: Ray Koopman <koopman at sfu.ca>
• Date: Sun, 3 Oct 2010 03:38:21 -0400 (EDT)
• References: <i84aed\$h0e\$1@smc.vnet.net> <i86uvo\$hpk\$1@smc.vnet.net>

```On Oct 2, 2:45 am, Valeri Astanoff <astan... at gmail.com> wrote:
>
> Good day,
>
> I have to apologize for not being very clear about what I wanted.
> Seems that you, Bob, were the only one to understand what I meant.
> [I had to replace SplitBy with Split cause I only have version 6]
> Any way I have to thank everyone who tried and help me.
> Maybe this test will more explicit than my poor previous example :
> [...]

I think I understand now what you're doing.

In:= Dimensions[a1 = Table[{{x,y}, RandomInteger},
{x, 0, 99}, {y, 0, 99}]]
Out= {100, 100, 2}

In:= Dimensions[a2 = Flatten /@ Flatten[a1, 1]]

Out= {10000, 3}

In:= unflatten[arr : {{_, _, _} ..}] := Module[{f},
Scan[(f[#[], #[]] = #[]) &, arr];
Table[{{x, y}, f[x, y]},
{x, arr[[All, 1]] // Union},
{y, arr[[All, 2]] // Union}]]

In:= {Timing@Dimensions[a3 = unflatten[a2]], a3 == a1}

Out= {{1.24, {100, 100, 2}}, True}

In:= unflattenBob[arr : {{_, _, _} ..}] := Split[
{Most[#],Last[#]}& /@ arr, #1[[1,1]] == #2[[1,1]] &]

In:= {Timing@Dimensions[a3 = unflattenBob[a2]], a3 == a1}

Out= {{0.12, {100, 100, 2}}, True}

In:= unflattenRay[arr_] := Partition[Transpose@
{arr[[All,{1,2}]],arr[[All,3]]},Length@Union@arr[[All,2]]]

In:= {Timing@Dimensions[a3 = unflattenRay[a2]], a3 == a1}

Out= {{0.02, {100, 100, 2}}, True}

```

• Prev by Date: Re: How to extract ImageSize?
• Next by Date: Mathematica crash when exporting to HTML? is it me?
• Previous by thread: Re: How to unflatten an array ?
• Next by thread: Re: How to unflatten an array ?