如何仅计算 Octave 中矩阵乘积的对角线? [英] How to compute only the diagonal of a matrix product in Octave?

查看:26
本文介绍了如何仅计算 Octave 中矩阵乘积的对角线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Octave 有没有办法只计算和存储矩阵乘积的对角线?

基本上喜欢做:vector = diag(A*B);

除了对角线上的值,我不关心 A*B 的任何值.矩阵大小约为 80k x 1212 x 80k,因此即使我不关心速度/额外内存,它也无法放入 RAM.

奇怪,因为 Octave 是一个大数据集的包,对角线很重要,所以应该是可以的.

解决方案

对角线的第一个元素是A的第一行与B的第一列的标量积.对角线的第二个元素是标量积A的第二行与B的第二列.

换句话说:

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

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 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.

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

解决方案

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);

这篇关于如何仅计算 Octave 中矩阵乘积的对角线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆