向量化算术运算

编程入门 行业动态 更新时间:2024-10-10 07:28:51
本文介绍了向量化算术运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过将一些迭代转换为Matlab中的矩阵运算来提高代码的性能.其中之一是以下代码,我需要弄清楚如何避免在操作中使用循环.

I am trying to improve the performance of my code by converting some iterations into matrix operations in Matlab. One of these is the following code and I need to figure out how can I avoid using loop in the operation.

此处gamma_ic&弓是二维矩阵. c& z是从外部迭代中设置的变量.

Here gamma_ic & bow are two dimensional matrices. c & z are variables set from outer iterations.

for z=1:maxNumber, for c=1:K, n = 0; for y2=1:number_documents, n = n+(gamma_ic(y2,c)*bow(y2,z)); end mu(z,c) = n / 2.3; end end

感谢您的帮助.

编辑.添加了c和z的循环.迭代一直进行到gamma_ic& amp;中的最大索引为止.弓.添加了mu,这是另一个二维矩阵,用于显示n的用法.

Edit. Added The loop for c and z. The iteration goes on till the maximum indices in gamma_ic & bow. Added mu which is another two dimensional matrix to show usage of n.

推荐答案

这应该对您有用,以获得mu,这似乎是所需的输出-

This should work for you to get mu, which seems to be the desired output -

mu = bow(1:number_documents,1:maxNumber).'*gamma_ic(1:number_documents,1:K)./2.3

更多推荐

向量化算术运算

本文发布于:2023-11-30 15:44:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650557.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算术

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!