Re: Matrix multiplication again... [message #80069 is a reply to message #80067] |
Tue, 08 May 2012 11:08  |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Monday, 7 May 2012 17:40:49 UTC+2, Mats Löfdahl wrote:
> Suppose I have an image (let's say 128x128=16384 pixels) and for each pixel there is a vector with maybe 100 (could be more) elements. I organize this as a variable x with 16384 by 100 elements.
>
> Suppose I also have a 100x100 matrix M (or in general not symmetric but nevermind) and I want to calculate y, which is then also a 16384 by 100 array where
>
> y[i,*] = M ## x[i,*]
Why don't you simply use: y = M##x ? Should work fine.
Or possibly y=transpose(M)##x depending on how you organized your M matrix.
"rows" and "columns" are rather confusing terms in IDL... Which does not stop Excelis VIS from using them in their documentation of # and ##, of course.
I stopped thinking about matrix multiplication the ordinary way (rows and columns) in IDL. Too confusing. To avoid having to remember which dimension is the "row" and which is the "column", I just memorized the following two rules (actually I try to use only the first one if possible):
** Rule #1 **
A ~ fltarr(M, N)
B ~ fltarr(N, P)
=> size(A # B, /dimensions) ~ [M, P]
i.e. second dimension of A is "dotted" with first dimension of B.
** Rule ##2 **
A ~ fltarr(N,M)
B ~ fltarr(P,N)
=> size(A ## B, /dimensions) ~ [P, M]
i.e. first dimension of A is "dotted" with second dimension of B.
PS: To keep things even more confusing, both operators have special cases if one of the arrays is a one dimensional array, and yet another special case if both vectors are one dimensional (an outer product will be calculated.) *sigh*
--
Yngvar
|
|
|