Re: Removing repeating array values [message #48101] |
Tue, 28 March 2006 13:26 |
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 #48104 is a reply to message #48103] |
Tue, 28 March 2006 12:43  |
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  |
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  |
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/
|
|
|