【发布时间】:2017-01-26 01:50:13
【问题描述】:
我有兴趣使用来自另一个 Eigen::VectorXd 向量的值来初始化一个 Eigen::VectorXd 向量,基于索引的 vector<int> 将指出将使用哪些元素。
也就是说,
// This is the large vector from which I'll take the values to
// initialize the second, shorter one
int N = 100;
Eigen::VectorXd V(N);
V.setRandom(N);
// This is the vector of indexes that'll be used to specify
// which elements of V will be used in the initialization of x
vector<int> ids = {1, 3, 0, 20};
// This is the vector I want to initialize
Eigen::VectorXd x(ids.size());
现在,我想要 x 是:
x(0) = V(1)
x(1) = V(3)
x(2) = V(0)
x(4) = V(20)
非常感谢!
【问题讨论】:
标签: c++ vector initialization eigen