|
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  |
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  |
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
|
|
|