Matlab高效稀疏矩阵乘法
Matlab efficient sparse matrix multiplication
我有一个稀疏矩阵,它只有三个对角线的元素。例如。
我还有一个列向量,我希望将稀疏矩阵每一行中的每个元素乘以列向量每一行中的相应元素。在 MATLAB 中有没有一种有效的方法来做到这一点?如果稀疏矩阵叫做A
,列向量叫做B
,我只试过
A.*repmat(B,[1,9])
这显然是低效的。
这是一种方法:
C = bsxfun(@times, A, B)
根据docs,得到的矩阵C
是稀疏的:
Binary operators yield sparse results if both operands are sparse, and full results if both are full. For mixed operands, the result is full unless the operation preserves sparsity. If S is sparse and F is full, then S+F, S*F, and F\S are full, while S.*F and S&F are sparse. In some cases, the result might be sparse even though the matrix has few zero elements.
我有一个稀疏矩阵,它只有三个对角线的元素。例如。
我还有一个列向量,我希望将稀疏矩阵每一行中的每个元素乘以列向量每一行中的相应元素。在 MATLAB 中有没有一种有效的方法来做到这一点?如果稀疏矩阵叫做A
,列向量叫做B
,我只试过
A.*repmat(B,[1,9])
这显然是低效的。
这是一种方法:
C = bsxfun(@times, A, B)
根据docs,得到的矩阵C
是稀疏的:
Binary operators yield sparse results if both operands are sparse, and full results if both are full. For mixed operands, the result is full unless the operation preserves sparsity. If S is sparse and F is full, then S+F, S*F, and F\S are full, while S.*F and S&F are sparse. In some cases, the result might be sparse even though the matrix has few zero elements.