MathGroup Archive 2011

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

Search the Archive

Re: Delete elements from list..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116624] Re: Delete elements from list..
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Tue, 22 Feb 2011 04:41:59 -0500 (EST)

Below assumes entries are machine size integers in order to use Compile. Variations might be used to handle different sets.

In[62]:= deleteLessersC = Compile[{{ll, _Integer, 1}},
   Module[{max = First[ll] - 1},
    Pick[ll, Map[If[# > max, max = #; 1, 0] &, ll], 1]]];

In[63]:= deleteLessersC[mylist]

Out[63]= {1, 2, 3, 4, 5, 6, 7, 8, 9}

In[64]:= biglist = RandomInteger[10^6, 10^6];
Timing[rising = deleteLessersC[biglist];]

Out[65]= {0.3439999999999999, Null}

Daniel Lichtblau
Wolfram Research

----- Original Message -----
> From: "Maarten van der Burgt" <Maarten.VanDerBurgt at kla-tencor.com>
> To: mathgroup at smc.vnet.net
> Sent: Monday, February 21, 2011 6:30:31 PM
> Subject: [mg116616] Delete elements from list..
> Hallo,
> 
> I have a list like:
> 
> mylist = {1, 2, 3, 4, 5, 6, 4, 5, 7, 8, 9}
> 
> I want to delete any element which is not strictly larger than the
> previous element, until my new list has only increasing values.
> 
> This means in mylist above I want to delete the 4 and the 5 at
> position
> 7 and 8.
> 
> Any elegant and fast way for doing this?
> 
> In practice I want to do this for a large amount (1000) of very large
> lists (1000). So speed is important.
> 
> Thanks for your help.
> 
> Maarten


  • Prev by Date: Re: Vector Runge-Kutta ODE solver with compilation?
  • Next by Date: Re: FinancialData Function Not Working for Property "Members"
  • Previous by thread: Delete elements from list..
  • Next by thread: Re: Delete elements from list..