I have an Eigen Array2Xd
and I want to put each of its rows into std::vector<double>
.
The spline_knots
is an Array2Xd of size (2, 4) with following values:
Array2Xd spline_knots(2, 4);
spline_knots << -1, 0, 30.57, 60.83,
0, 0, 9.73, 15.44;
I tried the following based on this answer:
vector<double> knot_xs(spline_knots.row(0).data(),
spline_knots.row(0).data() + spline_knots.row(0).size());
vector<double> knot_ys(spline_knots.row(1).data(),
spline_knots.row(1).data() + spline_knots.row(1).size());
However trying to copy each row into a vector with the above code I get the following result, which is very weird (first row begins with the correct elements, then zeros; second row has only zeros and ends with the third element of first row):
kont_xs: -1 0 0 0
knot_ys: 0 0 0 30.57
What is wrong here, and how can I create the vector from a row of the 2D array without a loop?