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.
1 Answer. You can use either todense() or toarray() function to convert a CSR matrix to a dense matrix.
Matrices that contain mostly zero values are called sparse, distinct from matrices where most of the values are non-zero, called dense.
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.
Let's declare two matrices:
SparseMatrix<double> spMat;
MatrixXd dMat;
Sparse to dense:
dMat = MatrixXd(spMat);
Dense to sparse:
spMat = dMat.sparseView();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With