Does MATLAB optimize diag(A*B)?

前端 未结 4 979
予麋鹿
予麋鹿 2021-01-05 10:00

Say I have two very big matrices A (M-by-N) and B (N-by-M). I need the diagonal of A*B. Computing the full A*B requires M

4条回答
  •  逝去的感伤
    2021-01-05 10:53

    You can compute only the diagonal elements without a loop: just use

    sum(A.'.*B).'
    

    or

    sum(A.*B.',2)
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题