       Re: How to unflatten an array ?

• To: mathgroup at smc.vnet.net
• Subject: [mg112851] Re: How to unflatten an array ?
• From: Valeri Astanoff <astanoff at gmail.com>
• Date: Sun, 3 Oct 2010 05:40:58 -0400 (EDT)
• References: <i84aed\$h0e\$1@smc.vnet.net> <i86uvo\$hpk\$1@smc.vnet.net> <i89btu\$jf6\$1@smc.vnet.net>

```On 3 oct, 09:38, Ray Koopman <koop... at sfu.ca> wrote:
> 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}

Good day,

My "unflatten" was a tortoise, your own is a hare !
This is going to be very useful.
Many thanks (to you and other posters).
--
Valeri

```

• Prev by Date: Re: Help to solve an integral by using Mathematica Integrate[Sqrt[t
• Next by Date: How to get Tooltip value
• Previous by thread: Re: How to unflatten an array ?
• Next by thread: Help for solving this Integrate[Sqrt[t*(1-t)* (t-z),{t,0,z} ] NEW!!!!