Re: reducing the time of constructing a List
- To: mathgroup at smc.vnet.net
- Subject: [mg57560] Re: [mg57533] reducing the time of constructing a List
- From: Adriano Pascoletti <pascolet at dimi.uniud.it>
- Date: Wed, 1 Jun 2005 06:01:50 -0400 (EDT)
- References: <200505310900.FAA03434@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On a 800Mhz iMac, Mathematica 5.1, OS X 10.4.1 I get
dat = Table[Random[Integer, {0, 10}], {100000}];
In[12]:=
lst1=Replace[dat,{x_/;x=!=1 \[Rule]0},{1}];//Timing
Out[12]=
{0.396968 Second,Null}
Adriano Pascoletti
Il giorno 31 mag 2005, alle ore 11:00, marloo3 at mail15.com ha scritto:
> 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
>
>
-
Messaggio controllato dal sistema antivirus del Dipartimento di Matematica e Informatica dell'Universita' degli Studi di Udine.
Email scanned by the antivirus system of the Department of Mathematics and Informatics of the University of Udine (Italy).