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

Home » Public Forums » archive » Re: another request for help with getting rid of for loops...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: another request for help with getting rid of for loops... [message #49752] Tue, 15 August 2006 22:00
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Benjamin Hornberger <benjamin.hornberger@stonybrook.edu> writes:
> And as a side note, you should better use [] instead of () for array
> subscripting. Check the IDL help index for "subscripts" -> "syntax".

Suit yourself whippersnapper :-)

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: another request for help with getting rid of for loops... [message #49762 is a reply to message #49752] Tue, 15 August 2006 07:18 Go to previous message
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
davede10@gmail.com wrote:
> Hi everyone,
> i read alot about eliminating for loops in idl , and yet i can't get
> rid of this simple loop .
> here is what i'm trying to do (multiply each plane in a data cube by a
> number):
> any idea?
>
> A=fltarr(100,100,10) ;my data cube
> A(*,*,*)=1.
> b=findgen(10) ;just a culumn of numbers
> c=a
> for i=0.9 do c(*,*,i)=A(*,*,i)*B(i)

a = findgen(100,100,10)
b = findgen(10)
c = transpose(rebin(b, 10, 100, 100, /sample))
c = a*c

(Using findgen makes it easier to verify the result by searching the
old and new method for differences).

Maarten
Re: another request for help with getting rid of for loops... [message #49763 is a reply to message #49762] Tue, 15 August 2006 07:10 Go to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
davede10@gmail.com wrote:
> Hi everyone,
> i read alot about eliminating for loops in idl , and yet i can't get
> rid of this simple loop .
> here is what i'm trying to do (multiply each plane in a data cube by a
> number):
> any idea?
>
> A=fltarr(100,100,10) ;my data cube
> A(*,*,*)=1.
> b=findgen(10) ;just a culumn of numbers
> c=a
> for i=0.9 do c(*,*,i)=A(*,*,i)*B(i)
>
> thanks,
> david
>

Here is the solution:

http://www.dfanning.com/tips/rebin_magic.html

Keep in mind, however, that once the arrays reach a certain size, your
computer might not be able to allocate the memory for the intermediate
"blown-up" array any more and the loop is suddenly orders of magnitude
faster than the pure array operation.

And as a side note, you should better use [] instead of () for array
subscripting. Check the IDL help index for "subscripts" -> "syntax".

Good luck,
Benjamin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: functions to access ETOPO2 or other bathymetric data sets?
Next Topic: Can these nested loops be made to run faster?

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

Current Time: Wed Oct 08 13:43:43 PDT 2025

Total time taken to generate the page: 0.00432 seconds