MATLAB中带有spfun的稀疏矩阵乘法 [英] Sparse matrix multiplication in MATLAB with spfun

查看:484
本文介绍了MATLAB中带有spfun的稀疏矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小为(m,1)的密集列矩阵y和一个大小为(m,n)的稀疏矩阵x.
我想使用yx的每一列进行按元素的乘法. 所得的稀疏矩阵的大小仍为(m,n).
加载到内存中的稀疏矩阵x约为10GB.
spfun可以帮助我以记忆有效的方式实现目标吗?

I have a dense column matrix y of size (m,1) and a sparse matrix x of size (m,n).
I want to do element-wise multiplication using y and every column of x.
The resultant sparse matrix is still of size (m,n).
Sparse matrix x, when loaded into memory, is about 10GB.
Can spfun help me accomplish my goal in a memory efficient manner?

我很难理解其背后的逻辑.

I am having difficulties understanding the logic behind it.

谢谢.

推荐答案

您是否尝试过?

out = bsxfun( @times, x, y ); 


spfun 更适用于元素明智的操作,其中您可以操纵x的每个非零元素.它不完全适合矩阵矢量元素明智的操作.
但是,如果您想沿这条路线做某事,则可以尝试:


spfun is more suitable for element-wise operations where you manipulate each non-zero element of x. It is not exactly fit for matrix-vector element wise operations.
However, if you want to do something along this line, you might try:

[ii jj xij] = find(x); %// extract non-zeros of x and their locations
out = sparse( ii, jj, xij.*y(ii), size(x,1), size(x,2) );

有关更多信息,请参见 doc find .

See doc find for more information.

这篇关于MATLAB中带有spfun的稀疏矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆