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

Home » Public Forums » archive » confused multiplying arrays
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
confused multiplying arrays [message #73482] Thu, 11 November 2010 13:11 Go to next message
paulartcoelho is currently offline  paulartcoelho
Messages: 30
Registered: March 2007
Member
hello,

i've got two arrays:

IDL> help,area,fluxes
AREA FLOAT = Array[2000]
FLUXES FLOAT = Array[2000, 112864]

I want the i-th element in area AREA[i] to multiply all elements in
the corresponding 2nd dimension in fluxes FLUXES[i,*] and then sum up
all the 2000 resulting fluxes, i.e., using loop:

for i = 0,1999 do begin
TOTAL_FLUX = TOTAL_FLUX + AREA[i]*reform(FLUXES[i,*])
endfor

i've been trying to figure out (without success) how to compute
TOTAL_FLUX without the loop using TOTAL(). ideas?

thx
p.
Re: confused multiplying arrays [message #73550 is a reply to message #73482] Fri, 12 November 2010 08:21 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Nov 12, 2:10 pm, Paula <paulartcoe...@gmail.com> wrote:
> living and learning... :)
> thanks for the tips about the matrix multiplications operators, they
> were new to me.

That is indeed the best option. I should have noticed that array
operation was equivalent to a product.

By the way, for cases when operands must be transposed before the
product, there is the matrix_multiply() function, which has keywords
to specify that one or both operands must be transposed, to save the
memory and time that would be consumed by transposing large things.
Re: confused multiplying arrays [message #73551 is a reply to message #73482] Fri, 12 November 2010 08:10 Go to previous message
paulartcoelho is currently offline  paulartcoelho
Messages: 30
Registered: March 2007
Member
living and learning... :)
thanks for the tips about the matrix multiplications operators, they
were new to me.
Re: confused multiplying arrays [message #73558 is a reply to message #73482] Fri, 12 November 2010 06:30 Go to previous message
David Gell is currently offline  David Gell
Messages: 29
Registered: January 2009
Junior Member
On Nov 11, 3:11 pm, Paula <paulartcoe...@gmail.com> wrote:
> hello,
>
> i've got two arrays:
>
> IDL> help,area,fluxes
> AREA            FLOAT     = Array[2000]
> FLUXES          FLOAT     = Array[2000, 112864]
>
> I want the i-th element in area AREA[i] to multiply all elements in
> the corresponding 2nd dimension in fluxes FLUXES[i,*] and then sum up
> all the 2000 resulting fluxes, i.e., using loop:
>
> for i = 0,1999 do begin
>      TOTAL_FLUX = TOTAL_FLUX + AREA[i]*reform(FLUXES[i,*])
> endfor
>
> i've been trying to figure out (without success) how to compute
> TOTAL_FLUX without the loop using TOTAL(). ideas?
>
> thx
> p.

Use the matrix multiply operator, TOTAL_FLUX=TOTAL(AREA # FLUXES).

IDL can be a little confusing about matrix multiplication. It has two
operators # and ## that perform the operation.
A#B = B##A.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Good-bye Contour Command
Next Topic: Alternative to cell_fill?

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

Current Time: Wed Oct 08 20:05:50 PDT 2025

Total time taken to generate the page: 0.02172 seconds