Re: more looping trouble
- To: mathgroup at smc.vnet.net
- Subject: [mg85451] Re: more looping trouble
- From: "Steve Luttrell" <steve at _removemefirst_luttrell.org.uk>
- Date: Mon, 11 Feb 2008 06:06:27 -0500 (EST)
- References: <fomjsd$hsj$1@smc.vnet.net>
Stop trying to use loops! Read up about the use of patterns and replacement rules in Mathematica. You need to define a replacement rule that matches each entry in your list, and then replaces it by the corresponding entry with the last element removed. There are lots of patterns you could use to achieve this effect, and here is one that I have written (rather verbosely to illustrate some of the things can be done - look them up in the documentation) to achieve the effect that you want: {{1,2,3}, {2,3,4}}/.{x_?NumberQ, y_?NumberQ, _?NumberQ}->{x, y} {{1, 2}, {2, 3}} There are other ways of obtaining the result you seek, all of which involve Mathematica operations applied to whole lists rather than using loops to address individual list elements. Stephen Luttrell West Malvern, UK "Francis Bitonti" <frankb.mail at gmail.com> wrote in message news:fomjsd$hsj$1 at smc.vnet.net... > Sorry for these lame questions but I'm still trying to get my head around > loops. I though I had it but I hit a snag today. > > I have a table of numbers {{1,2,3},{2,3,4}} I want to use a loop to remove > the third integer in each set and reassemble them as a new table. > However, something is going wrong I think it's because i'm not grasping > some > fundamental idea about how to perform these type of operations on tables. > > CLICK THIS LINK TO VIEW MY NOTEBOOK IN HTML FORMAT > http://www.fadarch.com/math/test.html<http://www.fadarch.com/math/test.html> > > > > > > -- > > _Francis Bitonti > web: http://www.fadarch.com/ > >