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: [mg57600] Re: reducing the time of constructing a List
  • From: "Peltio" <peltio at trilight.zone>
  • Date: Wed, 1 Jun 2005 06:04:47 -0400 (EDT)
  • References: <d7haeo$3pa$1@smc.vnet.net>
  • Reply-to: "Peltio" <peltioNOSPAM at despammed.com.invalid>
  • Sender: owner-wri-mathgroup at wolfram.com

someone wrote


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

This is a list that turns every element not 1 into a zero.
Create a function to do so

    f[1]=1;
    f[x_]=0;

and then map it onto your original list

    lst = f /@ dat

cheers,
Peltio


  • Prev by Date: Re: dendograms
  • Next by Date: Re: reducing the time of constructing a List
  • Previous by thread: Re: reducing the time of constructing a List
  • Next by thread: Re: reducing the time of constructing a List