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

Home » Public Forums » archive » Re: Finding duplicate values in an array
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: Finding duplicate values in an array [message #2582] Tue, 19 July 1994 12:12
andy is currently offline  andy
Messages: 31
Registered: November 1993
Member
In article <30goug$bkp@nyx10.cs.du.edu>, slohmeie@nyx10.cs.du.edu (stephen lohmeier) writes:
> In article <1994Jul18.171646@chapman.gsfc.nasa.gov>,
> Ian Sprod <sprod@chapman.gsfc.nasa.gov> wrote:
>>
>> I seem to remember the topic of finding duplicate values in an array
>> was discussed some months ago, but i never did read the end of the thread.
>>
>> What is the _fastest_ way to throw duplicated values out?
>>
>> thanks
>>
>> ian
>
> This is how I'd do it:
>
> ;array of values
> arr = [.14, .11, .13, .12, .13, .13, .12, .13, .09, .13, .10, .12, .09, .14]
>
> ;sort array
> arr_sorted = arr(sort(arr))
>
> ;find disparity between adjacent elements
> n = n_elements(arr_sorted)
> disparity = arr_sorted(1:n-1)-arr_sorted(0:n-2)
>
> ;find locations where disparities are non-zero
> index = where(disparity)+1
>
> ;non-duplicated array
> arr_nodups = [arr_sorted(0), arr_sorted(index)]
>
> END
>
> Hope this helps.
>
>


How about this...

arr = [.14, .11, .13, .12, .13, .13, .12, .13, .09, .13, .10, .12, .09, .14]
arr_nodups = arr(uniq(arr,sort(arr)))

Andy

--
,__o Andrew F. Loughe (Mail Code 971)
-\_<, NASA Goddard Space Flight Center phone: (301) 286-5899
(*)/'(*) Greenbelt, MD 20771 email: andy.loughe@gsfc.nasa.gov
Re: Finding duplicate values in an array [message #2585 is a reply to message #2582] Tue, 19 July 1994 07:45 Go to previous message
slohmeie is currently offline  slohmeie
Messages: 2
Registered: July 1993
Junior Member
In article <1994Jul18.171646@chapman.gsfc.nasa.gov>,
Ian Sprod <sprod@chapman.gsfc.nasa.gov> wrote:
>
> I seem to remember the topic of finding duplicate values in an array
> was discussed some months ago, but i never did read the end of the thread.
>
> What is the _fastest_ way to throw duplicated values out?
>
> thanks
>
> ian

This is how I'd do it:

;array of values
arr = [.14, .11, .13, .12, .13, .13, .12, .13, .09, .13, .10, .12, .09, .14]

;sort array
arr_sorted = arr(sort(arr))

;find disparity between adjacent elements
n = n_elements(arr_sorted)
disparity = arr_sorted(1:n-1)-arr_sorted(0:n-2)

;find locations where disparities are non-zero
index = where(disparity)+1

;non-duplicated array
arr_nodups = [arr_sorted(0), arr_sorted(index)]

END

Hope this helps.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: JPEG reader?
Next Topic: Re: JPEG reader?

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

Current Time: Wed Oct 08 13:41:40 PDT 2025

Total time taken to generate the page: 0.00648 seconds