Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: reducing the time of constructing a List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57546] Re: reducing the time of constructing a List
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 1 Jun 2005 06:01:30 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <d7haeo$3pa$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a) read in the manual the correct syntax for a 
For[] statement
   and write it down at least 100 times
b) forget all what you have read about For[] and 
Do[] and forget
   even that these functions exits
c) try
lst1 = If[# == 1, 1, 0] & /@ dat; // Timing

{0.031 Second, Null}

Regards
  Jens


<marloo3 at mail15.com> schrieb im Newsbeitrag 
news:d7haeo$3pa$1 at smc.vnet.net...
> please, what is the best way to reduce the 
> timing of the following lines, the
> source of data is:
> dat = Table[Random[Integer, {0, 10}], {100000}];
> and the purpose is to construct the List lst in 
> the following way:
> For[i = 1, i <= 100000,
>      If [dat[[i]] == 1,
>        lst = Join[lst, {1}], lst = Join[lst, 
> {0}]]; i++]; // Timing
>
> Out[]= {226.07 Second, Null}
> on the P4 celeron 2 Ghz , memory 382 MB ram
> thanks
> 



  • Prev by Date: Re: Block vs Module
  • Next by Date: Re: What is causing this error message?
  • Previous by thread: Re: reducing the time of constructing a List
  • Next by thread: Re: reducing the time of constructing a List