且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

矩阵乘法中的 bsxfun 实现

更新时间:2022-06-21 21:31:19

x 发送到三维,这样在使用 bsxfun 时,单例扩展就会生效对于与 A 的乘法,将乘积结果扩展到第三维.然后,执行bsxfun乘法-

Send x to the third dimension, so that singleton expansion would come into effect when bsxfun is used for multiplication with A, extending the product result to the third dimension. Then, perform the bsxfun multiplication -

val = bsxfun(@times,A,permute(x,[3 1 2])) 

现在,val 是一个 3D 矩阵,期望的输出是一个 2D 矩阵,通过第三维沿列连接.这是在下面实现的 -

Now, val is a 3D matrix and the desired output is expected to be a 2D matrix concatenated along the columns through the third dimension. This is achieved below -

out = reshape(permute(val,[1 3 2]),size(val,1)*size(val,3),[])

希望这是有道理的!传播 bsxfun 字!呜!!:)

Hope that made sense! Spread the bsxfun word around! woo!! :)