如何使用另一个"Eigen::VectorXd"向量中的值初始化"Eigen::VectorXd",基于索引的"向量<int>"
How to initialize an `Eigen::VectorXd` using values from another `Eigen::VectorXd` vector, based on a `vector<int>` of indexes
我有兴趣使用另一个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)
谢谢!
在 devel 分支(将变为 3.4)中,您可以执行以下操作:
x = V(ids);
在 Eigen 3.3 中,您必须编写自己的 for 循环。
相关文章:
- 写入向量<向量<bool>>
- 函数向量_指针有不同的原型,我可以构建一个吗
- std::向量与传递值的动态数组
- 将值指定给向量(2D)的向量中的某个位置
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 如何使用向量的template_back函数
- 尝试通过多个向量访问变量时,向量下标超出范围
- 如何通过派生类函数更改基类中的向量
- C++从另一个类访问公共静态向量的正确方法是什么
- 如何将ampl中的集合表示为c++中的向量
- 变量没有改变?通过向量的函数调用
- 迭代时从向量和内存中删除对象
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 计算排序向量的向量中唯一值的计数
- 矩阵向量乘法(cublasDgemv)返回零
- 一对向量构造函数:初始值设定项列表与显式构造
- 将结构向量排序为子组
- 在C++中调整向量中的索引
- 如何使用另一个"Eigen::VectorXd"向量中的值初始化"Eigen::VectorXd",基于索引的"向量<int>"