Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert sparse matrix to dense matrix in Eigen

Tags:

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

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

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.

like image 558
user2165656 Avatar asked Mar 18 '13 18:03

user2165656


People also ask

How do you make a sparse matrix dense?

1 Answer. You can use either todense() or toarray() function to convert a CSR matrix to a dense matrix.

What is the difference between dense and sparse matrix?

Matrices that contain mostly zero values are called sparse, distinct from matrices where most of the values are non-zero, called dense.

What is meant by dense matrix?

In quantum mechanics, a density matrix is a matrix that describes the quantum state of a physical system. It allows for the calculation of the probabilities of the outcomes of any measurement performed upon this system, using the Born rule.


1 Answers

Let's declare two matrices:

SparseMatrix<double> spMat;
MatrixXd dMat;

Sparse to dense:

dMat = MatrixXd(spMat);

Dense to sparse:

spMat = dMat.sparseView();
like image 150
ggael Avatar answered Oct 03 '22 23:10

ggael