如何将稀疏矩阵转换为密集矩阵 [英] How to convert sparse matrix to dense matrix in Eigen

查看:2584
本文介绍了如何将稀疏矩阵转换为密集矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单快捷的方法将稀疏矩阵转换为双精度矩阵?

Is there some easy and fast way to convert a sparse matrix to a dense matrix of doubles?

因为我的 SparseMatrix 不再稀疏,但在一些矩阵产品后变得密集。

Because my SparseMatrix is not sparse any more, but became dense after some matrix products.

我有另一个问题:Eigen库有优异的性能,这是怎么可能的?我不明白为什么,因为只有头文件,没有编译源。

Another question I have: The Eigen library has excellent performance, how is this possible? I don't understand why, because there are only header files, no compiled source.

推荐答案

让我们声明两个矩阵: p>

Let's declare two matrices:

SparseMatrix<double> spMat;
MatrixXd dMat;

稀疏到密集:

dMat = MatrixXd(spMat);

密集稀疏:

spMat = dMat.sparseView();

这篇关于如何将稀疏矩阵转换为密集矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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