MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   稀疏矩阵/内部矩阵维数 (https://www.labfans.com/bbs/showthread.php?t=26420)

poster 2019-12-14 20:13

稀疏矩阵/内部矩阵维数
 
好吧,尝试用搜索引擎做点什么。

我已经从5个文档的集合中生成了一个矩阵(term-document)。输出为:

docs = [B](5,1)1.0000(1,2)0.7071(3,2)0.7071(1,3)0.7071(5,3)0.7071(3,4)1.0000(4,5)1.0000[/B]

另外,我已经根据用户查询生成了查询矩阵。

q = [B](1,1)1(2,1)1[/B]

我正在尝试使用向量空间建模来查找与用户查询相似的文档集。代码如下:

% docs is a sprase matrix presenting a number of document. sc=zeros(1, n); doc_inds=zeros(1, n); % q is the user query. sc=q'*docs; %sort documents according to their similarity coefficient with the query [sc, doc_inds]=sort(sc); sc=sc(end:-1:1);doc_inds=doc_inds(end:-1:1); 行sc=q'*docs;总是产生错误说[B]:???内部矩阵尺寸必须[/B] 。 [B]同意。[/B]

谁能帮我解决这个问题?感谢您的时间。



[B]回答:[/B]

根据您示例中的数据, docs为5x5, q为2x1。矩阵乘法q'*docs试图将1x2矩阵与5x5矩阵相乘。矩阵乘法要求第一个矩阵的第二维与第二个矩阵的第一维一致,因此会出现误差。

为什么要在sc=zeros(1, n);行定义sc sc=zeros(1, n);然后用这个矩阵乘法覆盖它?



[url=https://stackoverflow.com/questions/5100742]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 02:58

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.