Re: fast way of appending x zeros to a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg79147] Re: [mg79090] fast way of appending x zeros to a list?
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 19 Jul 2007 03:42:25 -0400 (EDT)
- Reply-to: hanlonr at cox.net
data = Table[RandomInteger[5], {RandomInteger[{5, 10}]}] {5,0,0,5,3,1,3,4} numberOfZeroes = 5; Join[Table[0, {numberOfZeroes}], data] {0,0,0,0,0,5,0,0,5,3,1,3,4} % == PadLeft[data, Length[data] + numberOfZeroes] True Bob Hanlon ---- kristoph <kristophs.post at web.de> wrote: > Dear all, > > I'm looking for a fast way to append 0's to a list. Unfortunately, I > append a variable number of 0's to a list which is generated by a > For[...]-loop. Therefore, PadLeft[...] is not variable enough to > append exactly x zeros to the list. > > At the moment I use: Do[PrependTo[data,0],{K}] where the K depends on > certain factors. > > In case you have an idea to append exactly x zeros to the left quickly > I would be more that happy since I heard that the PrependTo[...] and > AppendTo[...] functions are very slow. > > Thanks a lot. > >
- Follow-Ups:
- Re: export data to spreadsheet
- From: Martin Channon <mgcqso@comcast.net>
- Re: export data to spreadsheet