Eigen: divida cada fila de matriz (escasa) por su elemento diagonal correspondiente
Frecuentes
Visto 1,392 equipos
3
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
tal que 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;
Gracias,
m.
1 Respuestas
5
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.
contestado el 28 de mayo de 14 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ matrix eigen sparse-matrix or haz tu propia pregunta.