Re: reducing the time of constructing a List
- To: mathgroup at smc.vnet.net
- Subject: [mg57562] Re: [mg57533] reducing the time of constructing a List
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 1 Jun 2005 06:02:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
You are just replacing non-unit entries in dat by 0. Use functional programming and forget For statements. dat = Table[Random[Integer, {0, 10}], {100000}]; lst = If[# == 1, 1, 0] & /@ dat; // Timing {0.05 Second, Null} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: marloo3 at mail15.com [mailto:marloo3 at mail15.com] To: mathgroup 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