我的大部分代码都使用Eigen,但我想使用GSL中的Miser或Vegas monte-carlo集成。我需要将特征向量转换成double的c数组,最好的方法是什么?
Matrix<double,3,1> --> c_array []发布于 2012-10-12 06:44:40
我以前和艾根一起工作过。
通常,为了简单地访问内部数组数据,比如mentioned by user janneb in this thread,您只需要invoke
Vector3d v;
// Operations to add values to the vector.
double *c_ptr = v.data();如果您希望迭代单个值来执行某些操作,则需要迭代每个索引行(.row(索引))和列(.col(索引)),这取决于您希望在目标向量中放置的矩阵顺序。
在您的特定示例中,您只需要迭代行:
Matrix<double,3,1> --> c_array []您可能希望调用.col(0)。如果出现类似的需求,the specific documentation is always helpful!
所以你会得到类似这样的结果(假设你想使用一个三行单列的矩阵):
Vector3d v;
// Operations to add values to the vector.
for (int i=0; i<v.rows(); ++i)
c_array[i] = v(i,0);希望这能帮上忙。
https://stackoverflow.com/questions/12849327
复制相似问题