Re: Mapping and AppendTo
- To: mathgroup at smc.vnet.net
- Subject: [mg91774] Re: Mapping and AppendTo
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 7 Sep 2008 05:40:17 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g9qimb$4fg$1@smc.vnet.net> <200809051113.HAA11749@smc.vnet.net> <g9t6op$jaj$1@smc.vnet.net>
Schettler, Martin wrote: > I would like mix use of Map and AppendTo in the following way (e.g.): > > M = {{0,1,2},{4,5,6,7}}; > AppendTo[#,8]&/@M; > > Of course, this doesn't work, because {0,1,2} is not a symbol name,etc. > Is there a way to use Hold or Sow to make this construct work? It would be less troublesome to use Append or Riffle and reset the value of M. For instance, In[1]:= M = {{0, 1, 2}, {4, 5, 6, 7}}; M = Append[#, 8] & /@ M Out[2]= {{0, 1, 2, 8}, {4, 5, 6, 7, 8}} In[3]:= M = {{0, 1, 2}, {4, 5, 6, 7}}; M = Riffle[#, 8, Length[#] + 1] & /@ M Out[4]= {{0, 1, 2, 8}, {4, 5, 6, 7, 8}} Regards, -- Jean-Marc
- References:
- Re: Magnetic field for a straight conductor with finite length -
- From: Jean-Marc Gulliet <jeanmarc.gulliet@gmail.com>
- Re: Magnetic field for a straight conductor with finite length -