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

Home » Public Forums » archive » dimension problem in 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
dimension problem in matrix multiplication [message #39029] Tue, 13 April 2004 11:29
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Hi all,

I have a 3-dimensional data array "image" (n_cols, n_rows, n_data) where
cols and rows denote pixels in a 2d-image and data are different data
values for each pixel. Now I would like to perform a matrix
multiplication so that the data vector (n_data elements) for each pixel
is multiplied by a 2-dimensional matrix "c".

If I try result = image # c, I get an "incompatible dimensions" error
since obviously IDL doesn't know that the 3rd dimension in "image" is
the vector I want to multiply by the matrix, and I want that operation
done for every pixel. Playing around with * and 0:n_data-1 subscripts
didn't help so far.

I could imagine a for loop to loop through all pixels, but does anybody
know a way how to avoid the loop? What I did before I found out about
matrix multiplication operators was doing the matrix multiplication
manually:

result = fltarr(n_cols, n_rows, n_data) ;; initialize
for i=0, n_data-1 do begin
for j=0, n_data-1 do begin
result[*, *, i] = result[*, *, i] + c[j, i] * image[*, *, j]
endfor
endfor

But I would like to avoid the for loops and use IDL's matrix
multiplication capabilities.

Any hints?

Thanks,
Benjamin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 2d where
Next Topic: interpol over huge cube

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

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

Total time taken to generate the page: 0.00435 seconds