eigen :: vectorXf到MatriXf映射 [英] eigen::vectorXf to MatriXf map

查看:2100
本文介绍了eigen :: vectorXf到MatriXf映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eigen c ++中,你如何
将一个vectorXf映射到一个matrixXf
(适当的维度)



href =http://eigen.tuxfamily.org/dox/TutorialMapClass.html =nofollow> docs 在
如何做到外部对象
所以我知道我们可以:



MatrixXf x_cen = Map< MatrixXf>(* x,* n,* p); / p>

但是如果 x VectorXf p>

解决方案

可以使用.data()成员函数,后跟Map:

  VectorXf vec(rows * cols); 
vec = ...;
Map< MatrixXf> vec_view_as_a_matrix(vec.data(),rows,cols);

然后你可以像任何Eigen对象一样使用vec_view_as_a_matrix,vec_view_as_a_matrix的修改也会报告给vec如果你想复制到一个新的MatrixXf对象,那么使用你写的结构:

  MatrixXf x_cen = Map< MatrixXf>(vec.data(),rows,cols); 


In eigen c++, how do you map a vectorXf to a matrixXf (of appropriate dimensions)

(there is good docs on how to do it for external objects so i know we can do:

MatrixXf x_cen=Map<MatrixXf>(*x,*n,*p);

but what if xis a VectorXf?

解决方案

You can use the .data() member function followed by Map:

VectorXf vec(rows*cols);
vec = ...;
Map<MatrixXf> vec_view_as_a_matrix(vec.data(), rows, cols);

Then you can use vec_view_as_a_matrix just like any Eigen objects, modifications to vec_view_as_a_matrix will be reported to vec as well since they are sharing the memory. If you want to copy to a new MatrixXf object, then use the construction you wrote:

MatrixXf x_cen = Map<MatrixXf>(vec.data(), rows, cols);

这篇关于eigen :: vectorXf到MatriXf映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆