Re: Converting 2D Lists to 3D lists
- To: mathgroup at smc.vnet.net
- Subject: [mg94963] Re: [mg94941] Converting 2D Lists to 3D lists
- From: "Scot T. Martin" <smartin at deas.harvard.edu>
- Date: Thu, 1 Jan 2009 07:26:20 -0500 (EST)
- References: <200812311108.GAA13561@smc.vnet.net>
Karthik, I think these show you how to do it: In[12]:= SampleList3D={{{-1,2},{0,1},{3,4}},{{-3,-2},{-1.5,2.5},{0.5,-.75}}} Out[12]= {{{-1,2},{0,1},{3,4}},{{-3,-2},{-1.5,2.5},{0.5,-0.75}}} In[18]:= Map[Append[#,5]&,SampleList3D,{2}] Out[18]= {{{-1,2,5},{0,1,5},{3,4,5}},{{-3,-2,5},{-1.5,2.5,5},{0.5,-0.75,5}}} In[19]:= ReplacePart[%,{2,2,3}->3] Out[19]= {{{-1,2,5},{0,1,5},{3,4,5}},{{-3,-2,5},{-1.5,2.5,3},{0.5,-0.75,5}}} On Wed, 31 Dec 2008, 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}}} > > > Some help, ideas, thoughts, tips please. Thanks in advance, > Karthik Sridhara > >