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

Home » Public Forums » archive » Re: Is it really more efficient to work with arrays than FOR loops?
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: Is it really more efficient to work with arrays than FOR loops? [message #51518 is a reply to message #51514] Thu, 23 November 2006 07:21 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
Well, you might want to express x and y as 2-dimensional arrays,
something like

n=400
x=findgen(n)#replicate(1,n)
y=transpose(x)

then you can write condition in the form

ind=where( x*a+y*b GE c)

and compute whatever you want to compute for
x[ind] and y[ind]...

Ciao,
Paolo

Alvin wrote:
> Hey all,
> I was wondering if it is really that more efficient to work with arrays
> (large ones that is). For example I have the following simple code,
> which takes about 30 min to run:
>
> FOR z=0L, 400 DO BEGIN
> FOR y=0L, 400 DO BEGIN
> FOR x=0L, 400 DO BEGIN
> fn=f(z) ;a function of z
> gn=f(z) ;another function of z
> IF ( f(z) * x + g(z) * y GE f(z) * g(z) ) THEN BEGIN
> blah
> blah
> blah
> ENDIF
> ENDFOR
> ENDFOR
> ENDFOR
>
> Now if I tried to vectorize the above, would it do me any good in
> saving time and possibly memory? If I say something like f(z) # x +
> g(z) # y, where these are all vectors, I have a feeling that I am not
> covering all the possible combinations as the FOR loop above. Does
> anyone have any ideas, or suggestions?
> Thanks,
> Alvin.
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Thanks!
Next Topic: Julian time problem

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

Current Time: Thu Oct 09 03:28:18 PDT 2025

Total time taken to generate the page: 0.87742 seconds