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: [mg79106] Re: fast way of appending x zeros to a list?
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Thu, 19 Jul 2007 03:21:10 -0400 (EDT)
  • References: <f7ke8n$508$1@smc.vnet.net>

kristoph schrieb:
> 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.

AppendTo and PrependTo are known to be very slow. It's better to
build up a nested list an Flatten it:

Do[data={0,data},{K}]; Flatten[data]

Gruss Peter
-- 
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: strange bug?
  • Next by Date: Re: fast way of appending x zeros to a list?
  • Previous by thread: Re: fast way of appending x zeros to a list?
  • Next by thread: Re: Re: fast way of appending x zeros to a list?