题
我正在寻找这样的东西:
fmat A = randu<fmat>(4,5);
float **a = A.to_array(); // Return matrix as float**
有谁知道如何做到这一点 Armadillo
?
解决方案
没有函数可以返回指针数组。你 能 访问底层缓冲区 memptr()
方法:
float *a = A.memptr();
您还可以使用以下命令获取指向任何矩阵列的指针 colptr()
方法. 。我不确定为什么您可能需要一组指针,但您可以构建这样的一个(未编译和未经测试的代码):
std::vector<float *> av;
av.reserve(A.n_cols);
for (unsigned int i = 0; i < A.n_cols; ++i)
av.push_back() = A.colptr(i);
float **a = &av[0]; // a remains valid while av is in scope
请注意,犰狳将数据存储在 列主序.
不隶属于 StackOverflow