comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Array element deletion
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Array element deletion [message #36386 is a reply to message #36385] Fri, 12 September 2003 06:31 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Edd Edmondson writes:

> Supposing I have a big array and I also have an array containing indices
> of unwanted elements. Is there a neat way of removing those elements from
> the array?
>
> Attempts using WHERE() have failed for me* and currently I'm looping
> through the array of indices and deleting them one at a time - which is
> fine when I've only got 20 or 30 of them but I doubt it'll scale well.

Here is a function from my web page:

FUNCTION SetDifference, a, b

; = a and (not b) = elements in A but not in B

mina = Min(a, Max=maxa)
minb = Min(b, Max=maxb)
IF (minb GT maxa) OR (maxb LT mina) THEN RETURN, a ;No intersection...
r = Where((Histogram(a, Min=mina, Max=maxa) NE 0) AND $
(Histogram(b, Min=mina, Max=maxa) EQ 0), count)
IF count eq 0 THEN RETURN, -1 ELSE RETURN, r + mina
END

Here is how it works. Suppose you have an array:

array = [3.5, 4.8, 9.3, 2.1, 7.6, 4.6]

And an array of indices you don't want:

bad = [2, 4]

You would do this:

possible = Indgen(N_Elements(array))
good = SetDifference(possible, bad)
Print, possible
Print, good
newArray = array[good]
Print, newArray

You can learn more about these set methods here:

http://www.dfanning.com/tips/set_operations.html

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Contour overlay
Next Topic: Re: Floating Point Slider Widgets

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 23:58:41 PDT 2025

Total time taken to generate the page: 0.80182 seconds