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

Home » Public Forums » archive » Count duplicate elements in an array but keep their order!
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: Count duplicate elements in an array but keep their order! [message #85751 is a reply to message #85750] Sat, 31 August 2013 08:03 Go to previous messageGo to previous message
Josh Sixsmith is currently offline  Josh Sixsmith
Messages: 13
Registered: December 2012
Junior Member
The following might work.
Using the UNIQ function will give the indices, which you can use to get the value counts.
To get the counts for each value you'll then need to use the SHIFT function to offset the indices in order subtract from the original indices.

Assuming that a is already sorted, other wise use SORT(a) first
un = UNIQ(a)

In order to get the proper count for the first value, the unique array will need to be extended by 1 element.

un_extra = intarr(n_elements(un)+1)
un_extra[1:n_elements(un_extra)-1] = un

Add 1 to the array to account for the fact that indices start at 0
un_extra += 1
un_offset = SHIFT(un_extra, -1)

counts = un_offset - un_extra

Remove the last element in counts
counts = count[0:n_elements(counts)-2]
values = a[un]

Hope that helps ,if it works :)

Cheers
Josh
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Evenly timed events in a widget program
Next Topic: Texture image on a 3d curve: cgsurface and xobjview problems

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

Current Time: Fri Oct 10 06:28:57 PDT 2025

Total time taken to generate the page: 0.21601 seconds