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

Home » Public Forums » archive » Re: The IDL way: Find last non-zero value
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: The IDL way: Find last non-zero value [message #67729 is a reply to message #67728] Mon, 24 August 2009 17:12 Go to previous messageGo to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Aug 24, 4:42 pm, Eric Hudson <ehud...@mit.edu> wrote:
> Thanks to all of you for the suggestions.  I timed them all on several
> of the larger matrices and found that the last suggestion (using
> cumulative totals) was about twice as fast as the previous ones, and
> about 5 times faster than the brute force loop.  It did depend on how
> many zeros ended each line on average.  When the number was small the
> loop could win, but for my typical matrices the cumulative total is
> the clear winner.
>
> Thanks again,
> Eric

I'm shocked that no one's suggested histogram! Here's my take, which
I'd wager does at least as well as the cumulative totals:

sz=size(array,/dimen)
ncol=sz[0]
nrow=sz[1]
evenrows = 2*lindgen(nrow)
h = histogram( (array ne 0) + rebin(reform(evenrows,
1,nrow),ncol,nrow), min=0, max=2*nrow-1, $
reverse_indices=ri)
result = ri[ri[evenrows+2]-1] mod ncol
w = where(h[evenrows+1] eq 0, nw)
if nw gt 0 then result[evenrows[w]]=-1

-Jeremy.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Histogram Too Many Array Elements
Next Topic: Integer - decimal help

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

Current Time: Fri Oct 10 09:33:11 PDT 2025

Total time taken to generate the page: 0.08115 seconds