another request for help with getting rid of for loops... [message #49764] |
Tue, 15 August 2006 06:53  |
davede10
Messages: 1 Registered: August 2006
|
Junior Member |
|
|
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
|
|
|
Re: another request for help with getting rid of for loops... [message #49873 is a reply to message #49764] |
Sat, 19 August 2006 13:51  |
Marshall Perrin
Messages: 44 Registered: December 2005
|
Member |
|
|
davede10@gmail.com <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)
Another trick you might want to know about is the zero subscript one:
for i=0,9 do c[0,0,i]=A[*,*,i]*B[i]
Doesn't look like it should work, does it? But it does, and is often
faster than the version with *'s on both sides, due to the way IDL
internally handles building array index lists.
- Marshall
|
|
|