Re: Converting 2D Lists to 3D lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg94977] Re: Converting 2D Lists to 3D lists*From*: Yves Klett <yves.klett at googlemail.com>*Date*: Thu, 1 Jan 2009 07:28:51 -0500 (EST)*References*: <gjfjr3$d7a$1@smc.vnet.net>

Karthik, one convenient, if not very fast way for numerical lists is to use a rule like e.g.: to3D[list_, z_] := list /. {x_?NumericQ, y_?NumericQ} :> {x, y, z} slist = {{{-1, 2}, {0, 1}, {3, 4}}, {{-3, -2}, {-1.5, 2.5}, {0.5, -.75}}} {{{-1, 2}, {0, 1}, {3, 4}}, {{-3, -2}, {-1.5, 2.5}, {0.5, -0.75}}} to3D[slist, 0] {{{-1, 2, 0}, {0, 1, 0}, {3, 4, 0}}, {{-3, -2, 0}, {-1.5, 2.5, 0}, {0.5, -0.75, 0}}} This is very useful for transforming sets of graphics primitives, since it works for points, lines and polygons straight away and you don=C2=B4t = have to worry about the structure of the set. Regards, Yves Karthik Sridhara schrieb: > 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 >