【问题标题】:How do I compute the sum of the outer products of all columns of a matrix in MATLAB without loops?如何在没有循环的情况下计算 MATLAB 中矩阵的所有列的外积的总和?
【发布时间】:2012-09-11 20:00:45
【问题描述】:

我试图让标题说明一切。

我有一个矩阵,我需要计算列组合的外积的总和。我知道如何使用 for 循环来做到这一点。但是,有没有一种矢量化的方式来做到这一点?

testData = rand(x);   
answer = zeros(x);
for i=1:x
  for j=1:x
    answer = answer + testData(:,i)'*testData(:,j);
  end
end

【问题讨论】:

标签: matlab matrix vectorization


【解决方案1】:

答案就在这个问题Fast Outer Product

answer = testData.'*testData;

注意这给出了的外积的总和。

【讨论】:

    猜你喜欢
    • 2013-02-07
    • 1970-01-01
    • 2016-10-31
    • 2014-12-14
    • 2013-01-11
    • 2017-06-14
    • 2023-03-03
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多