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

Home » Public Forums » archive » Re: general matrix multiplication
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: general matrix multiplication [message #10994] Mon, 23 February 1998 00:00
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Schmidt wrote:
>
> All,
>
> I'm looking for a routine to perform generalized matrix multipication
> over particular indexes within arrays. For example, let A be a
> (10,3,20) array and B be a (20,5,10,30) array. I want to be able to
> multiply and add (i.e. matrix multiply) the elemens within index 1,3 of
> A and 3,1 of B and produce a result of dimension (3,5,10). While this
> can be done simply by using FOR loops, I'm looking for a routine that
> does this efficiently, using built-in IDL routines. Does anyone know of
> such a routine? ...how I could construct such a routine?
>
> Thanks,
>
> David
> --

hmmm - I am not sure I understand how you will get a result with the
dimensions you indicate. Anyway, here some hints that will hopefully
help you a little:
While matrix multiplication is indeed provided by IDL with the
## operator (see online help:
"The ## operator does what is commonly referred to as matrix
multiplication. It computes array elements by multiplying the rows of
the first array by the columns of the second array. The second array
must have the same number of rows as the first array has columns. The
resulting array has the same number of rows as the first array and the
same number of columns as the second array."

I don't think you will have a chance to get around the loops over
3, 5, and 30. Your piece of code should be something like
result = fltarr(10,10,3,5,30)
for i=0,2 do begin
for j=0,4 do begin
for k=0,29 do begin
tmp = A(*,i,*) ## B(*,j,*,k)
result(*,*,i,j,k) = tmp
endfor
endfor
endfor


Regards,
Martin.


------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: variable types
Next Topic: Question about polygons in object graphics

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

Current Time: Wed Oct 08 19:25:08 PDT 2025

Total time taken to generate the page: 0.00864 seconds