Re: Converting 2D Lists to 3D lists

• To: mathgroup at smc.vnet.net
• Subject: [mg94958] Re: [mg94941] Converting 2D Lists to 3D lists
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Thu, 1 Jan 2009 07:25:26 -0500 (EST)

SampleList3D = {{{-1, 2}, {0, 1}, {3, 4}}, {{-3, -2}, {-1.5,
2.5}, {0.5, -.75}}};

Apply[{##, 5} &, SampleList3D, {2}]

{{{-1, 2, 5}, {0, 1, 5},
{3, 4, 5}}, {{-3, -2, 5},
{-1.5, 2.5, 5}, {0.5, -0.75, 5}}}

Map[Append[#, 5] &, SampleList3D, {2}]

{{{-1, 2, 5}, {0, 1, 5},
{3, 4, 5}}, {{-3, -2, 5},
{-1.5, 2.5, 5}, {0.5, -0.75, 5}}}

Map[Insert[#, 5, 3] &, SampleList3D, {2}]

{{{-1, 2, 5}, {0, 1, 5},
{3, 4, 5}}, {{-3, -2, 5},
{-1.5, 2.5, 5}, {0.5, -0.75, 5}}}

% == %% == %%%

True

Table[Apply[{##, {5, 3}[[n]]} &,
SampleList3D[[n]], {1}], {n, 2}]

{{{-1, 2, 5}, {0, 1, 5},
{3, 4, 5}}, {{-3, -2, 3},
{-1.5, 2.5, 3}, {0.5, -0.75, 3}}}

Table[{##, {5, 3}[[n]]} & @@@
SampleList3D[[n]], {n, 2}]

{{{-1, 2, 5}, {0, 1, 5},
{3, 4, 5}}, {{-3, -2, 3},
{-1.5, 2.5, 3}, {0.5, -0.75, 3}}}

% == %%

True

Bob Hanlon

On Wed, Dec 31, 2008 at 11:12 AM , Karthik Sridhara wrote:

> Hello Everyone,
>
> I want to know if there is a way to convert a 2D lists to 3D Lists.
> Below is the example list in list form:
>
> SampleList3D = {{{-1, 2}, {0, 1}, {3, 4}}, {{-3, -2}, {-1.5, 2.5},
> {0.5, -.75}}}
>
> I want the list to be intact but add 5 at the end of each sublist;
> This is how I want it to look:
>
> {{{-1, 2, 5}, {0, 1, 5}, {3, 4, 5}}, {{-3, -2, 5}, {-1.5, 2.5, 5},
> {0.5, -.75, 5}}}
>
> I also want to be able do the same as above but add 3 this time to the
> second column. This is how it should look.
> {{{-1, 2, 5}, {0, 1, 5}, {3, 4, 5}}, {{-3, -2, 3}, {-1.5, 2.5, 3},
> {0.5, -.75, 3}}}
>
> Is there any way I can do this? I have been trying to use Map and
> Insert but I am getting the wrong result.
>
> Insert[SampleList3d, x, {#, -1}] & /@ {1, 2} ;
>
> I get this result and this is not what I want:
> {{{{-1, 2}, {0, 1}, {3, 4},
>    x}, {{-3, -2}, {-1.5, 2.5}, {0.5, -0.75}}}, {{{-1, 2}, {0, 1}, {3,
>     4}}, {{-3, -2}, {-1.5, 2.5}, {0.5, -0.75}, x}}}
>
>