Eigen实现matlab中的reshape

本文详细介绍了Eigen库在3.4版本中如何进行矩阵重塑,包括2D视图的重塑和1D线性视图的创建。通过DenseBase::reshaped()函数,可以方便地将矩阵转换为不同尺寸的视图,而不改变原始数据。同时,也讨论了原地重排(resize)操作,需要注意其依赖于输入的存储顺序。示例代码展示了各种重塑和重排的方法及其效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://eigen.tuxfamily.org/dox-devel/group__TutorialReshape.html

注意,需要Eigen3.4版本


Since the version 3.4, Eigen exposes convenient methods to reshape a matrix to another matrix of different sizes or vector. All cases are handled via the DenseBase::reshaped(NRowsType,NColsType) and DenseBase::reshaped() functions. Those functions do not perform in-place reshaping, but instead return a view on the input expression.

Reshaped 2D views 2维矩阵的重排

The more general reshaping transformation is handled via: reshaped(nrows,ncols). Here is an example reshaping a 4x4 matrix to a 2x8 one:

例子1

code:注意,默认是列优先,matlab的reshape是列优先

Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped(2, 8):" <&l
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值