Search code examples
c++matrixeigensparse-matrix

Using Eigen/Sparse library in c++, is there a way to delete columns from a sparse matrix?


I have built a matrix which is n rows by n+4 columns, there are four specific columns which I would need to delete to make this into a square. Is there a way to do this with eigen? I have had a look at their Docs and I can't seem to find anything.

Thanks all,

Nick


Solution

  • You can use matrix multiplication, e.g.

    SparseMatrix<double> X(10,14);
    for (int i = 0; i<14; i++) X.coeffRef(0, i) += (double) (i+1);
    
    SparseMatrix<double> Y(14, 10); 
    for (int i = 0; i<10; i++)  Y.coeffRef(i, i) += 1.0;    
    
    cout << X*Y << endl << endl;