源代码:
#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;
}
答案 0 :(得分:4)
您无法将matrix_row
分配给vector
,需要进行一些转换:
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);
}