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

Home » Public Forums » archive » write more efficient for loop
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: write more efficient for loop [message #91633 is a reply to message #91632] Fri, 07 August 2015 06:50 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 8/7/15 7:25 AM, g.nacarts@gmail.com wrote:
> Hi
>
> I used the Profiler, /SYSTEM & Profiler to identify which part of
> the code takes long time. I am using nested for loop (takes about 1950 sec).
>
> N = 215L
>
> Image_2 = make_array(N,N,/double)
>
> for i=0L, N-1 do begin
> for j=0L, N-1 do begin
> x = round(i + A[i, j])
> y = round(j + B[i, j])
> if (x ge 0) && (y ge 0) then begin
> Image_2[i,j] = Image_1[x, y]
> endif
> endfor
> endfor
>
> I was wondering if there is a more efficient way to write the above.
> I don't have a lot of experience in programming.

Is image_1 n by n also? Here's some totally untested code, but hopefully
it provides some inspiration:

x = round(rebin(reform(findgen(n), 1), n, n) + a)
y = round(rebin(reform(1, findgen(n)), n, n) + b)
ind = where(x ge 0 and y ge 0, count)
if (count gt 0) then begin
image_2[ind] = image_1[x[ind], y[ind]]
endif

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: an urgent help of file conversio
Next Topic: rot and poly_2d question

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

Current Time: Wed Oct 08 16:05:05 PDT 2025

Total time taken to generate the page: 0.00182 seconds