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

Home » Public Forums » archive » 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
another request for help with getting rid of for loops... [message #49764] Tue, 15 August 2006 06:53 Go to next message
davede10 is currently offline  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 Go to previous message
Marshall Perrin is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: iplot, /xlog
Next Topic: Algorithm for lat/lon searching

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

Current Time: Wed Oct 08 13:40:33 PDT 2025

Total time taken to generate the page: 0.00679 seconds