将std与特征库中的Vectorxd一起使用

use std with Vectorxd from eigen library

本文关键字:Vectorxd 一起 std 特征      更新时间:2023-10-16

它是否可能像这样使用std::swap函数来替换特征库中VectorXd的元素?它正确吗?

   Eigen::VectorXd   val2;
   std::swap(val2[i], val2[k + i]); 

是的,您可以:

#include <iostream>
#include <algorithm>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
  VectorXd e_vec(5);
  e_vec << 1, 2, 3, 4, 5;
  std::swap(e_vec[0], e_vec[2]);
  std::cout << e_vec << std::endl;
  return 0;
}

产品:

3
2
1
4
5