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

Home » Public Forums » archive » Re: Removing repeating array values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Removing repeating array values [message #48101] Tue, 28 March 2006 13:26
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <MPG.1e934acb64c3cce6989be0@news.frii.com>, David Fanning <davidf@dfanning.com> writes:
> Jonathan Wolfe writes:
>
>> Is there an easier way than a for loop to remove repeating values
>> within an array? For example, I have two arrays and am trying to match
>> the closest value from one with the other using a where() statement.
>> When the where statement is returned, I have multiple instances of the
>> same value; however, I just want to keep one of these. A for loop
>> works, but computing speed is slow, I'm running on an old 700MHz PIII.
>> Do you know of a faster way? Thanks for the help!
>
> Removing elements from an array is tailor-made for
> the HISTOGRAM function. See the Histogram Tutorial for
> an example:
>
> http://www.dfanning.com/tips/histogram_tutorial.html
>
It sure is perfect for Histogram. For completeness, though, I've a
function (named SORPURGE) in my library that'll do the same, using a
single call to WHERE.

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: Removing repeating array values [message #48102 is a reply to message #48101] Tue, 28 March 2006 13:02 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Matt Savoie writes:

> It might be faster than learning histogram :)

Faster, but less useful in the long run. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Removing repeating array values [message #48103 is a reply to message #48102] Tue, 28 March 2006 12:50 Go to previous message
vorticitywolfe is currently offline  vorticitywolfe
Messages: 19
Registered: January 2006
Junior Member
Thanks guys! That worked!

~Jon
Re: Removing repeating array values [message #48104 is a reply to message #48103] Tue, 28 March 2006 12:43 Go to previous message
savoie is currently offline  savoie
Messages: 68
Registered: September 1996
Member
David Fanning <davidf@dfanning.com> writes:

> Jonathan Wolfe writes:
>
>> Is there an easier way than a for loop to remove repeating values
>> within an array? For example, I have two arrays and am trying to match
>> the closest value from one with the other using a where() statement.
>> When the where statement is returned, I have multiple instances of the
>> same value; however, I just want to keep one of these. A for loop
>> works, but computing speed is slow, I'm running on an old 700MHz PIII.
>> Do you know of a faster way? Thanks for the help!
>
> Removing elements from an array is tailor-made for
> the HISTOGRAM function. See the Histogram Tutorial for
> an example:
>
> http://www.dfanning.com/tips/histogram_tutorial.html
>
> Cheers,
>
> David


I responded privately at first, but thought other people might want this too.


Is UNIQ what you're looking for?
from the manual...
; Create an array:
array = [1, 2, 1, 2, 3, 4, 5, 6, 6, 5]

; Variable B holds an array containing the sorted, unique values in
; array:
b = array[UNIQ(array, SORT(array))]
PRINT, b
IDL prints

1 2 3 4 5 6



It might be faster than learning histogram :)

Just a thought.

Matt


--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
Re: Removing repeating array values [message #48105 is a reply to message #48104] Tue, 28 March 2006 12:40 Go to previous message
mchinand is currently offline  mchinand
Messages: 66
Registered: September 1996
Member
In article <1143577351.464281.41560@i39g2000cwa.googlegroups.com>,
Jonathan Wolfe <vorticitywolfe@gmail.com> wrote:
> Is there an easier way than a for loop to remove repeating values
> within an array? For example, I have two arrays and am trying to match
> the closest value from one with the other using a where() statement.
> When the where statement is returned, I have multiple instances of the
> same value; however, I just want to keep one of these. A for loop
> works, but computing speed is slow, I'm running on an old 700MHz PIII.
> Do you know of a faster way? Thanks for the help!
>
> Jon

See the UNIQ function. Your array has to be sorted or else you need to use the optional
index parameter.

--Mike


--
Michael Chinander, PhD
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
Re: Removing repeating array values [message #48106 is a reply to message #48105] Tue, 28 March 2006 12:30 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jonathan Wolfe writes:

> Is there an easier way than a for loop to remove repeating values
> within an array? For example, I have two arrays and am trying to match
> the closest value from one with the other using a where() statement.
> When the where statement is returned, I have multiple instances of the
> same value; however, I just want to keep one of these. A for loop
> works, but computing speed is slow, I'm running on an old 700MHz PIII.
> Do you know of a faster way? Thanks for the help!

Removing elements from an array is tailor-made for
the HISTOGRAM function. See the Histogram Tutorial for
an example:

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

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Removing repeating array values
Next Topic: Re: problem using p.multi in IDL 5.3/IRIX

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

Current Time: Wed Oct 08 17:36:41 PDT 2025

Total time taken to generate the page: 0.00518 seconds