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

Home » Public Forums » archive » set all elements in 2d array between some range to 1
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: set all elements in 2d array between some range to 1 [message #91085 is a reply to message #91028] Tue, 02 June 2015 20:37 Go to previous messageGo to previous message
havok2063 is currently offline  havok2063
Messages: 24
Registered: December 2012
Junior Member
Hi Jeremy,

Thanks a lot for your help. This is great. Exactly the solution I'm looking for. Hmm..my original loop is taking me ~30 seconds. Not sure why yours is much faster. Here is my code. Actually it seems it's because the 10.^loglam is being done every loop iteration. Changing this to a stored variable, the loop takes 2.1 seconds.

starttime = systime(/seconds)
for j=0,nlines-1 do begin
index=where((10.^loglam gt skylines[j].skywave-skypad)and(10.^loglam lt skylines[j].skywave+skypad),nindex)
f (nindex gt 0) then skylinemask[index]=1
endfor
print, (systime(/seconds)-starttime)
30.812672

I really like your code, since it's faster and no loops. However, when I run it, I'm getting some small differences between the output from the original vs the new method.

IDL> help, where(skylinemask)
<Expression> LONG = Array[226935]

IDL> help, where(skylinemask_v2)
<Expression> LONG = Array[226933]

IDL> help, where(skylinemask ne skylinemask_v2)
<Expression> LONG = Array[14]

Printing these 14 elements for both the old and new mask shows that are flipped from each other. Could it be a boundary issue?

Cheers, Brian
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Function graphics and IDL widgets
Next Topic: Identify whether value is integer in IF statement

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

Current Time: Sat Oct 11 08:58:25 PDT 2025

Total time taken to generate the page: 0.80053 seconds