views:

49

answers:

3

Is there a way in octave to compute and store only the diagonal of a matrix product?

Basically like doing vector = diag(A*B);

I don't care about any of the values of A*B except those on the diagonal. The matrix to around 80k x 12 and 12 x 80k. So even if I didn't care about the speed/extra memory it simply wont fit in RAM.

Strange, since octave is a package for huge data sets and diagonals are very important, so it should be possible.

+1  A: 

The first element in the diagonal is the scalar product of the first row of A with the first column of B. The second element in the diagonal is the scalar product of the second row of A with the second column of B.

In other words:

vector = sum(A.*B',2);
Jonas
I see you made good use of the 5 minute grace period for editing. ;)
gnovice
I'm glad the grace period exists. I seem to only see my major mistakes once I hit submit. :)
Jonas
+2  A: 

This is how you could do it in MATLAB (probably similar to Octave syntax):

vector = sum(A.*B',2);

This will compute only the resulting diagonal of the operation A*B as a column vector vector.

gnovice
A: 

actually I think it's the dot product of the first row of A with the first column of B... the second diagonal element is the dot product of the second row and the second column... etc

vicatcu
Yep. I mistyped.
Jonas

related questions