Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Delete elements from list..
Replies: 17   Last Post: Mar 8, 2011 5:37 AM

 Messages: [ Previous | Next ]
 Maarten van der Burgt Posts: 10 Registered: 5/7/10
Re: Delete elements from list..
Posted: Feb 24, 2011 6:29 AM

Hallo,

Thanks everybody who replied to my questions.

The real problem I have is just a bit more complex than my simplified
example.
My list is in fact a numerical 2D list like mylist1 == {{x_0, y_0},
{x_1,y_1},... {x_i, y_i}, ...{x_N, y_N}}.
The xi are strictly increasing and the yi should be as well. Due to some
measurement errors it can happen that this is not the case. I simply
want to delete the {xi, yi} pairs where y_i <== y_i-1. That way I end up
with a list, mylist2, where also the y_i are strictly increasing.
(that way I can make an Interpolation[Reverse/@mylist2] in order to have
a function x_i(y_i)).

first look and the variety of the answers it seems that there is
definitely something which should help.

Maarten

-----Original Message-----
From: Achilleas Lazarides [mailto:achilleas.lazarides@gmx.com]
Sent: Wednesday, 23 February, 2011 11:22
Subject: Re: Delete elements from list..

Do you really want the resulting list to only have increasing elements?
then something like

Module[{tmpl == mylist[[1]]},
Scan[(If[# > tmpl, Sow[#]; tmpl == #]) &,
mylist]; // Reap]

should work (except that it eats the first element).

If you actually meant that you want to delete any element that is not
strictly larger than the previous, then

Module[{tmpl == mylist[[1]]},
Scan[(If[# > tmpl, Sow[#]]; tmpl == #) &,
mylist]; // Reap]

(which again eats the first element).

On Feb22, 2011, at 1:30 AM, Maarten van der Burgt wrote:

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

Date Subject Author
2/21/11 Maarten van der Burgt
2/22/11 Bill Rowe
2/22/11 Bob Hanlon
2/22/11 Ray Koopman
3/7/11 Borut Levart
3/8/11 Peter Pein
2/22/11 DrMajorBob
2/22/11 James Stein
2/22/11 lshifr@gmail.com
2/22/11 Daniel Lichtblau
2/23/11 Achilleas Lazarides
2/24/11 Maarten van der Burgt
2/25/11 Ray Koopman
2/26/11 DrMajorBob
2/26/11 Ray Koopman
2/27/11 Maarten van der Burgt
2/27/11 Ray Koopman
3/8/11 DrMajorBob