define a boost::ublas matrix with a given vector

293 views Asked by At

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.

1

There are 1 answers

0
panda-34 On

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.