将Eigen::VectorXd类型转换为std::vector
typecasting Eigen::VectorXd to std::vector
他们有很多链接可以反过来,但在我的特定情况下,我找不到从Eigen::Matrix或Eigen::VectorXd中获得std::向量。
vector<int> vec(mat.data(), mat.data() + mat.rows() * mat.cols());
你不能打字,但你可以很容易地复制数据:
VectorXd v1;
v1 = ...;
vector<double> v2;
v2.resize(v1.size());
VectorXd::Map(&v2[0], v1.size()) = v1;
您可以从和到特征向量进行此操作:
//init a first vector
std::vector<float> v1;
v1.push_back(0.5);
v1.push_back(1.5);
v1.push_back(2.5);
v1.push_back(3.5);
//from v1 to an eignen vector
float* ptr_data = &v1[0];
Eigen::VectorXf v2 = Eigen::Map<Eigen::VectorXf, Eigen::Unaligned>(v1.data(), v1.size());
//from the eigen vector to the std vector
std::vector<float> v3(&v2[0], v2.data()+v2.cols()*v2.rows());
//to check
for(int i = 0; i < v1.size() ; i++){
std::cout << std::to_string(v1[i]) << " | " << std::to_string(v2[i]) << " | " << std::to_string(v3[i]) << std::endl;
}
相关文章:
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- std::vector的包装器,使数组的结构看起来像结构的数组
- 编译器如何区分std::vector的构造函数
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 在std::vector上存储带有模板的类实例
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么std::vector比数组慢
- std::vector::迭代器是否可以合法地作为指针
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 为什么std::vector和std::valarray初始化构造函数不同
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 在没有未定义行为的情况下实现类似std::vector的容器
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- 使用 std::vector::reverse_iterator 将 int 序列化为字节向量?
- 如何将AERT_Allocate与 std:vector 一起使用
- 推导 std::vector::back() 的返回类型
- 如何将原始字节附加到 std::vector?
- std::vector 没有重载函数的实例与参数列表匹配
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?