diagproduct.m

来自「人工神经网络的源码编程」· M 代码 · 共 35 行

M
35
字号
function d = diagProduct(X, Y)%  d = diagProduct(X, Y)%%  Outputs the diagonal of the product of X and Y.%  Faster than diag(X*Y).%%  Inputs%%    X    matrix (m-by-n)%    Y    matrix (n-by-m)%%  Output%    d    vector (m-by-1)[m,n] = size(X);[p,q] = size(Y);if m ~= q | n ~= p  error('diagProduct: bad dimensions')end% P - a column vector of the rows of XP = X';P = P(:);% Q - a column vector of the columns of YQ = Y(:);% Z - an [n,m] matrix containing the components of P.*QZ = zeros(n,m);Z(:) = P .* Q;% d - the answer is the sum of the columns of Zd = colSum(Z)';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?