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

Home » Public Forums » archive » Re: fastest way to find the first non-zero value in an array
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: fastest way to find the first non-zero value in an array [message #59678 is a reply to message #59675] Tue, 08 April 2008 01:42 Go to previous messageGo to previous message
Clemens is currently offline  Clemens
Messages: 1
Registered: April 2008
Junior Member
it depends on the size of array. Small array is a simple loop.
Huge one can be :

index_arr = where( arr NE 0)
print, index_arr[0]

on very huge arrays you can devide arr into big peaces.

Clemens

<smasson@locean-ipsl.upmc.fr> schrieb im Newsbeitrag
news:ff3bf651-8707-47e8-8cff-5e694dd5622f@m71g2000hse.google groups.com...
> Hi,
>
> I want to find the first non-zero value of an array. Is there a faster
> way to do this than with the "where" command: (where(array ne 0))[0]
> "Where" will look for all non-zero values and I only need the first
> one. It would be great if I could stop "where" in its search process
> as soon as it found one element...
>
> sebastien
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: array concatenation in 2-D
Next Topic: Re: Avoiding FOR loops (version googleplex.infinity)

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

Current Time: Thu Oct 09 03:00:16 PDT 2025

Total time taken to generate the page: 1.03850 seconds