MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: fast way of appending x zeros to a list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79140] Re: fast way of appending x zeros to a list?
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Thu, 19 Jul 2007 03:38:48 -0400 (EDT)

On 7/18/07 at 2:58 AM, kristophs.post at web.de (kristoph) wrote:

>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.

On my machine PadLeft is far faster than this Do loop

In[5]:= data = Table[RandomReal[], {10}];

In[6]:= Timing[PadLeft[data, 10010, 0];]

Out[6]= {0.000438,Null}

In[7]:= test = data;

In[8]:= Timing[Do[PrependTo[data, 0], {10000}];]

Out[8]= {1.09508,Null}

In[9]:= data == PadLeft[test, 10010, 0]

Out[9]= True

In[10]:= $Version

Out[10]= 6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007)
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Coding an inverse permutation
  • Next by Date: Re: Style of inserted Text via Drawing Tools
  • Previous by thread: Re: export data to spreadsheet
  • Next by thread: Re: fast way of appending x zeros to a list?