0

I am looking for a way to define a nxm matrix from a given 1xm vector in boost::ublas. I try the following code

boost::numeric::ublas::vector<double> v(100);
boost::numeric::ublas::matrix<double> m(10, 100);
std::copy(v.begin(), v.end(), m.begin2());

but this will only copy the vector to the first row of the matrix. What I want is to duplicate v to rows so each row of M identical to a v. So besides looping each row and run copy 10 times, is that any better way to do so? Thanks.

user1285419
  • 2,183
  • 7
  • 48
  • 70

1 Answers1

0

Short of looping, you may do it like this:

m = outer_prod(scalar_vector<double>(10, 1), v);

although it's probably not the most optimal, performance-wise.

panda-34
  • 4,089
  • 20
  • 25