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

Home » Public Forums » archive » Re: matrix multiplication of 2 three-dimensional arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: matrix multiplication of 2 three-dimensional arrays [message #62044 is a reply to message #62043] Wed, 20 August 2008 09:11 Go to previous messageGo to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Aug 20, 8:22 am, "thomas.jagdhuber" <thomas.jagdhu...@gmail.com>
wrote:
> Dear experts,
>
> I would like to matrix multiply two matrices with dimensions
> [3,3,1500]. means: 1500 times a matrix multiplication of 2 matrices
> with dimension [3,3]
> I could do this with a for loop over the dimension [1500] but i
> suppose this is not very elegant. Is there any other way to do this
> time-efficient.
>
> Best regards,
>
> thomas

My IDL-foo feels strong today... let's see:

If A and B are 3x3, then C = A ## B is equivalent to:

q = rebin(indgen(3),3,3)
p = rebin(reform(indgen(3),1,3),3,3)
c = total(rebin(reform(a[q,p],1,3,3),3,3,3) * reform(b[*,q],3,3,3), 2)

Adding an extra dimension on the end of that gets tricky, but I think
the following should work if A and B are each 3x3xNMATRIX and you want
C to be a 3x3xNMATRIX array where each C[*,*,i] = A[*,*,i] ##
B[*,*,i]:

c = total(rebin(reform( (a[q,p,*])[0:2,3*lindgen(3),*],1,3,3,nmatrix),
3,3,3,nmatrix) * reform(b[*,q,*],
3,3,3,nmatrix), 2)

Incidentally, does anyone have a better way of doing the (a[q,p,*])
[0:2,3*lindgen(3),*] bit of it? The problem is that if A, Q and P are
each 3x3 then A[Q,P] is 3x3, but if A is 3x3xN then A[Q,P,*] is 9x9xN.

If I see another reform today, I'm going to scream. ;-)

-Jeremy.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: strange behaviour of SOCKET
Next Topic: overplot crosses with numbers for reference

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

Current Time: Sat Oct 11 11:35:46 PDT 2025

Total time taken to generate the page: 2.57334 seconds