Taylor
Taylor

Reputation: 2085

Converting Eigen array to Eigen vector

Is there anything wrong with this? Eigen's documentation says its vectors are just matrices with one of the dimensions set to size 1. But I would prefer a .vector() method.

Eigen::VectorXd tmpVec(5);
tmpVec << 1,2,3,4,5;
Eigen::VectorXd result = tmpVec.array().matrix();
std::cout << result << "\n";

Upvotes: 2

Views: 7478

Answers (1)

ggael
ggael

Reputation: 29255

The methods .array() and .matrix() permits to change the semantic from matrix-linear-algebra to plain-array and vice-versa. So having both a .vector() and a .matrix() to describe the same change of semantic would be rather cumbersome.

Upvotes: 7

Related Questions