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

Home » Public Forums » archive » histogram question
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: Histogram question [message #40360 is a reply to message #26139] Mon, 09 August 2004 07:39 Go to previous messageGo to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
> .. However, this time around I have a third
> array, v3. v3[i] corresponds to a distinct number of counts at the
> position [v1[i], v2[i]]. So, when I do the histogram, I want to use the
> value found in v3
> .. v1 = [0, 1, 0, 2, 0, 2, 2, 1, 0]
> v2 = [1, 1, 2, 2, 0, 1, 2, 0, 0]
> v3 = [3, 0, 2, 0, 1, 1, 4, 2, 1]
>
> ans=[[2, 2, 0],
> [3, 0, 1],
> [2, 0, 4]]
> Anyone know of an efficient way to do this? I figure there's some trick
> you can do with histogram to achieve this effect, but I am no where near
> the histogram guru like others on this list. -Mike

There are some things that HISTOGRAM can't do (no, really). TOTAL and
WHERE can help you a bit. I can get the loop down to the total number of
bins in the histogram (in this case there really isn't any speed
inprovement, hopefully you have more elements than bins in the real data?)

If your data has lots of zeros in v3 then this method gets more
efficient than the 'count everything' approach because the zeros are
silently ignored. (If your resulting histogram is sparse another, more
tedious optimisation, can be made by doing a HIST_2D(v1,v2) before hand)

v1 = [0, 1, 0, 2, 0, 2, 2, 1, 0]
v2 = [1, 1, 2, 2, 0, 1, 2, 0, 0]
v3 = [3, 0, 2, 0, 1, 1, 4, 2, 1]

n=n_elements(v1)
;build an index array
index=fltarr(n)
index=v2*(max(v1)+1)+v1
;m=the number of bins in the 2d histogram
m=max(index)+1
;tot=the 2d histogram
tot=fltarr(m)

for i=0, m-1 do begin & $
w=where(index eq i,c) & $
if(c gt 0) then tot[i]=tot[i]+total(v3[w]) & $
endfor

tot=reform(tot, max(v1)+1, max(v2)+1)
;
;

Chris.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Contour Border Sort Error
Next Topic: Passing Structures with Pointers with Call_External

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

Current Time: Sat Oct 11 14:29:26 PDT 2025

Total time taken to generate the page: 0.79969 seconds