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

Home » Public Forums » archive » Use of ++ operator to count frequency of an entry (Was: Majority Voting)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Use of ++ operator to count frequency of an entry (Was: Majority Voting) [message #65473] Sun, 08 March 2009 06:26 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Hi,

A couple of weeks ago it was pointed out that the ++ operator used in a
vectorised form would work on repeated indices meaning that it's
possible to do this:

IDL> a=[1,2]
IDL> ++a[[0,0,0,1,0,0]]
IDL> print,a
6 3

here a[0] has been incremented five times because the index 0 appears
five times.

It was pointed out that this meant that David's mode calculation example of:

array = [1, 1, 2 , 4, 1, 3, 3, 2, 4, 5, 3, 2, 2, 1, 2, 6, -3]
distfreq = Histogram(array, MIN=Min(array))
maxfreq= Max(distfreq)
mode = Where(distfreq EQ maxfreq) + Min(array)
Print, mode

could be re-written as:

array = [1, 1, 2 , 4, 1, 3, 3, 2, 4, 5, 3, 2, 2, 1, 2, 6,-3]
f=intarr(max(array)-min(array)+1)
f[array-min(array)]++
junk=max(f,idx)
mode=idx + min(array)
print,mode

(in fact I see David's article on this has already been updated to
include the ++ solution). It was also shown that this solution wasn't
any slower than using histogram. It's not necessarily better but in
certain situations could be easier to read.

Anyway, it was pointed out that this meant that a++ behaves differently
from a+=1 which some people didn't like and others didn't mind. Some of
us (ok, mainly me) worried that using this behaviour of the ++ operator
leading to problems later if it turned out that the behaviour wasn't
intended by ITTVIS and they would try to rationalise ++ with +=.

I volunteered to contact them to query if the behaviour was intended and
if it could be considered future-proof. The response included:

"the output of the following commands seem to be the expected one (and
should not change in the future)

a = [1, 2]
a [[0, 0, 1, 0]]++
print,a"

so, as promised, this is me sharing the result of the query with the
rest of the group. Everyone can feel safe about relying on the ++
operator to work on repeated indices.

Thanks,

Allan
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: CORRELATE where is the problem?
Next Topic: Re: Problem with labeling contour lines in IDL

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

Current Time: Wed Oct 08 17:15:45 PDT 2025

Total time taken to generate the page: 0.00460 seconds