如何仅在八度中计算矩阵乘积的对角线? [英] How to compute only the diagonal of a matrix product in Octave?
问题描述
八度中是否有一种方法可以仅计算和存储矩阵乘积的对角线?
Is there a way in Octave to compute and store only the diagonal of a matrix product?
基本上喜欢这样做:vector = diag(A*B);
除了对角线上的那些值,我不在乎A*B
的任何值.矩阵大小在80k x 12
和12 x 80k
左右,所以即使我不在乎速度/额外的内存,它也根本无法放入RAM.
I don't care about any of the values of A*B
except those on the diagonal. The matrix sizes are 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.
奇怪,因为Octave是用于存储大量数据集的程序包,对角线非常重要,所以应该有可能.
Strange, since Octave is a package for huge data sets and diagonals are very important, so it should be possible.
推荐答案
对角线上的第一个元素是A的第一行与B的第一列的标量积.对角线上的第二个元素是标量积A的第二行和B的第二列.
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.
换句话说:
vector = sum(A.*B',2);
这篇关于如何仅在八度中计算矩阵乘积的对角线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!