Initialise Eigen::vector with std::vector

前端 未结 5 1317
独厮守ぢ
独厮守ぢ 2020-12-01 01:59

I have seen it done before but I cannot remember how to efficiently initialize an Eigen::Vector of known length with a std::vector of the same leng

5条回答
  •  心在旅途
    2020-12-01 02:32

    Just to extend @ggael answer in case others didn't notice it:

    From Quick Reference Guide: Mapping External Array:

    float data[] = {1,2,3,4};
    Map v1(data);       // uses v1 as a Vector3f object
    Map  v2(data,3);     // uses v2 as a ArrayXf object
    Map m1(data);       // uses m1 as a Array22f object
    Map m2(data,2,2);   // uses m2 as a MatrixXf object
    

提交回复
热议问题