Using the Eigen library in C++, given a sparse matrix A
, what is the most efficient way (row-wise operations? how to?) to compute a sparse matrix B
such that B(i, j) = A(i, j) / A(i, i)
? That is, divide each row i
by the corresponding diagonal element A(i, i)
. It would be helpful to know how to do it both in-place (replacing entries in A
) and out-of-place (creating a new sparse matrix B
).
My sparse matrix is defined as:
typedef double Real;
typedef Eigen::SparseMatrix<Real> SparseMatrixR;
Thank you,
m.
In other words you want to extract the diagonal of A, view it as a diagonal matrix, and apply its inverse to A:
A = A.diagonal().asDiagonal().inverse() * A;
This operation should be slightly more efficient if A is rowmajor.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.