Matlab: Argmax and dot product for each row in a matrix

元气小坏坏 提交于 2019-12-01 22:17:51

Dot product is essentially matrix multiplication:

[~, Y] = max(W*X');

bsxfun based approach to speed-up things for you -

[~,Y] = max(sum(bsxfun(@times,X,permute(W,[3 2 1])),2),[],3)

On my system, using your dataset I am getting a 100x+ speedup with this.


One can think of two more "closeby" approaches, but they don't seem to give any huge improvement over the earlier one -

[~,Y] = max(squeeze(sum(bsxfun(@times,X,permute(W,[3 2 1])),2)),[],2)

and

[~,Y] = max(squeeze(sum(bsxfun(@times,X',permute(W,[2 3 1]))))')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!