Eigen 为 Matrix 、Array 和  Vector提供了块操作方法。块区域可以被用作 左值 和 右值。在Eigen中最常用的块操作函数是 .block() 。

block() 方法的定义如下:

  block of size (p,q) ,starting at (i,j)。matrix.block(i,j,p,q);     matrix.block<p,q>(i,j);

上述两种形式都可以被用在固定大小和动态大小的矩阵中。

  举例如下:

  

 #include <iostream>
#include <eigen3/Eigen/Dense> using namespace Eigen;
using namespace std; int main(int argc ,char** argv)
{
MatrixXf m(,);
m << ,,,,
,,,,
,,,,
,,,;
cout<<"Block in the middle"<<endl;
cout<<m.block<,>(,)<<endl<<endl;
for(int i = ; i <= ; ++i)
{
cout<<"Block of size "<<i<<" x "<<i<<endl;
cout<<m.block(,,i,i)<<endl<<endl;
}
return ;
}

  

  block也可以被用作左值,即block可以进行赋值操作。

  举例如下:

  

 #include <iostream>
#include <eigen3/Eigen/Dense> using namespace Eigen;
using namespace std; int main(int argc ,char** argv)
{
Array22f m;
m << ,,
,; Array44f a = Array44f::Constant(0.6);
cout<<"Here is the array a"<<endl<<a<<endl<<endl;
a.block<,>(,) = m;
cout<<"Here is now a with m copoed into its central 2x2 block"<<endl<<a<<endl<<endl;
a.block(,,,) = a.block(,,,);
cout<<"Here is now a with bottom-right 2x3 copied into top-left 2x3 block:"<<endl<<a<<endl<<endl;
return ;
}

  运行结果如下:

  

  特殊情况下的块操作,比如取整行或者整列,取上面的若干行或者底部的若干行。

  取 整行和整列的操作如下:

    matrix.row(i);

matrix.col(j);

   访问矩阵的行和列的操作如下:

  

 #include <iostream>
#include <eigen3/Eigen/Dense> using namespace Eigen;
using namespace std; int main(int argc ,char** argv)
{
MatrixXf m(,);
m << ,,,
,,,
,,;
cout<<"Here is the matrix m:"<<endl<<m<<endl;
cout<<"2nd Row: "<<m.row()<<endl;
m.col() += *m.col();
cout<<"After adding 4 times the first column into the third column,the matrix m is:\n";
cout<<m<<endl;
return ;
}

Eigen 还提供了以下对 角点 等特殊块操作方法:

  

  矩阵的块操作:

  

  举例如下;

  

 #include <iostream>
#include <eigen3/Eigen/Dense> using namespace Eigen;
using namespace std; int main(int argc ,char** argv)
{
ArrayXf v();
v << ,,,,,;
cout<<"v.head(3) = "<<endl<<v.head()<<endl<<endl;
cout<<"v.tail<>() = "<<endl<<v.tail<>()<<endl<<endl;
v.segemnt(,) *= ;
cout<<"after v.segemt(1,4) *= 2,v="<<endl<<v<<endl; return ;
}

  运行结果如下:

  

最新文章

  1. 搭建TFS 2015 Build Agent环境(一)
  2. 关于learntorank http://qiita.com/rockhopper/items/bb3d46f01df5f6499123
  3. Gulp: Getting Started
  4. 安卓开发第一步:Android Studio安装配置
  5. BZOJ 3309: DZY Loves Math
  6. DataInputStream类和RandomAccessFile类的使用方法
  7. [Hibernate] - Select/Update/Delete/Insert
  8. win8 任务栏不合并隐藏标题
  9. POJ2503Babelfish
  10. Linux功能-RPM命令详解
  11. Android设计模式之命令模式、策略模式、模板方法模式
  12. java基础语法笔记
  13. Li Fei-fei写给她学生的一封信,如何做好研究以及写好PAPER
  14. JavaScript常用内置对象(window、document、form对象)
  15. VS2015企业版本(安装包+key)
  16. MVC多模板支持
  17. 分布式队列神器 Celery
  18. MyBatis:二级缓存原理分析
  19. CPU的系统总线
  20. Linux学习笔记:Jenkins安装

热门文章

  1. Dubbo-Centos7管控台安装
  2. Linux-(touch,cat,nl,more|less,head|tail)
  3. haproxy配置文件详解--转
  4. json 只能用 for-in 遍历
  5. ruby大神与菜鸟的代码区别
  6. vue-webpack 做出来的项目部署到服务器上,点开是空白页(我这里把项目发布到git上)
  7. .NET创建WebService服务简单的例子
  8. unity 判断平台(安卓,iOS还是编辑器)
  9. MySQL6:视图
  10. Java版分布式ID生成器技术介绍