0
  • I am trying to copy matrix rows to a vector of vectors how can I apply it?
  • Is it possible to convert boost matrix to vector of vectors?

source code:

#include <iostream.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <vector>

int main()
{
    //declare vector and matrix
    std::vector<std::vector<float>> document;
    boost::numeric::ublas::matrix<float> data(10,10);
    // fill matrix (any numbers)
    for (size_t i = 0; i < data.size1(); i++)
    {
        for (size_t j = 0; j < data.size2(); j++)
        {
            data(i,j) = i + j ;
        }
    }

    //The problem is here. I want to copy data(j) to document i.e document.push_back(data(j)). How can I copy matrix rows to a vector?
  //I know that it's wrong: document.push_back(data(j)) but that's almost what i am trying to do

//matrix_row<matrix<double> > mr (m, i); allows me to access a row right?

return 0;

}

1 Answer 1

4

You can't assign a matrix_row to a vector, it need some conversion:

for(size_t i = 0; i < data.size1(); ++i)
{
    std::vector<float> row(data.size2());
    boost::numeric::ublas::matrix_row<boost::numeric::ublas::matrix<float> > mr (data, i); 

    std::copy(mr.begin(), mr.end(), row.begin());
    document.push_back(row);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.