Re: Re: Apply function to parts of a list
- To: mathgroup at smc.vnet.net
- Subject: [mg86355] Re: [mg86336] Re: Apply function to parts of a list
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 9 Mar 2008 05:02:41 -0500 (EST)
- Reply-to: hanlonr at cox.net
Better data = {{x1, y1, z1, f1, g1, h1}, {x2, y2, z2, f2, g2, h2}, {x3, y3, z3, f3, g3, h3}, {xn, yn, zn, fn, gn, hn}}; ReplacePart[#, 2 -> #[[2]] + 10] & /@ data {{x1, y1 + 10, z1, f1, g1, h1}, {x2, y2 + 10, z2, f2, g2, h2}, {x3, y3 + 10, z3, f3, g3, h3}, {xn, yn + 10, zn, fn, gn, hn}} Bob Hanlon ---- Bob Hanlon <hanlonr at cox.net> wrote: > data = {{x1, y1, z1, f1, g1, h1}, {x2, y2, z2, f2, g2, h2}, > {x3, y3, z3, f3, g3, h3}, {xn, yn, zn, fn, gn, hn}}; > > numberOfDimensions = Length[data[[1]]]; > > s = ReplacePart[Table[0, {numberOfDimensions}], > 2 -> 10]; > > s + # & /@ data > > {{x1, y1 + 10, z1, f1, g1, h1}, > {x2, y2 + 10, z2, f2, g2, h2}, > {x3, y3 + 10, z3, f3, g3, h3}, > {xn, yn + 10, zn, fn, gn, hn}} > > > Bob Hanlon > > ---- guerom00 <guerom00 at gmail.com> wrote: > > Thank you very much for all the answers ! Great ! > > > > More generally now : Again I have a list of list but with more > > "dimensions" Something like that : > > > > data={{x1,y1,z1,f1,g1,h1},{x2,y2,z2,f2,g2,h2},{x3,y3,z3,f3,g3,h3},... > > {xn,yn,zn,fn,gn,hn}} > > > > And let's say I wanna, for the sake of the example, add 10 to all the > > y's i.e. I want > > > > {{x1,y1+10,z1,f1,g1,h1},{x2,y2+10,z2,f2,g2,h2},{x3,y3+10,z3,f3,g3,h3},... > > {xn,yn+10,zn,fn,gn,hn}} > > > > According to all your suggestions, I could do > > > > {#1,#2+10,#3,#4,#5,#6}& @@@ data > > > > Right ? Isn't there another simpler way (imagine instead of 6 elements > > (x,y,z,f,g,h), I have 100 !) > >