Eigen(6)快操作
1. 块操作
块是matrix或array中的矩形子部分。
2. 使用块
函数.block(),有两种形式
operation |
构建一个动态尺寸的block |
构建一个固定尺寸的block |
起点(i,j)块大小(p,q) |
.block(i,j,p,q) |
.block< p,q >(i,j) |
Eigen中,索引从0开始。
两个版本都可以用于固定尺寸和动态尺寸的matrix/array。功能是等价的,只是固定尺寸的版本在block较小时速度更快一些。
int main(){Eigen::MatrixXf m(4,4);m << 1, 2, 3, 4,5, 6, 7, 8,9,10,11,12,13,14,15,16;cout << "Block in the middle" << endl;cout << m.block<2,2>(1,1) << endl << endl;for (int i = 1; i <= 3; ++i){cout << "Block of size " << i << "x" << i << endl;cout << m.block(0,0,i,i) << endl << endl;}}
输出
Block in the middle
6 7
10 11
Block of size 1x1
1
Block of size 2x2
1 2
5 6
Block of size 3x3
1 2 3
5 6 7
9 10 11
作为左值
int main(){Array22f m;m << 1,2,3,4;Array44f a = Array44f::Constant(0.6);cout << "Here is the array a:" << endl << a << endl << endl;a.block<2,2>(1,1) = m;cout << "Here is now a with m copied into its central 2x2 block:" << endl << a << endl << endl;a.block(0,0,2,3) = a.block(2,1,2,3);cout << "Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:" << endl << a << endl << endl;}
输出
Here is the array a:
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
Here is now a with m copied into its central 2x2 block:
0.6 0.6 0.6 0.6
0.6 1 2 0.6
0.6 3 4 0.6
0.6 0.6 0.6 0.6
Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:
3 4 0.6 0.6
0.6 0.6 0.6 0.6
0.6 3 4 0.6
0.6 0.6 0.6 0.6
3. 行和列
Operation |
Method |
ith row |
matrix.row(i) |
jth colum |
matrix.col(j) |
int main(){Eigen::MatrixXf m(3,3);m << 1,2,3,4,5,6,7,8,9;cout << "Here is the matrix m:" << endl << m << endl;cout << "2nd Row: " << m.row(1) << endl;m.col(2) += 3 * m.col(0);cout << "After adding 3 times the first column into the third column, the matrix m is:\n";cout << m << endl;}
输出
Here is the matrix m:
1 2 3
4 5 6
7 8 9
2nd Row: 4 5 6
After adding 3 times the first column into the third column, the matrix m is:
1 2 6
4 5 18
7 8 30
4. 角相关操作
operation |
dynamic-size block |
fixed-size block |
左上角p\*q |
matrix.topLeftCorner(p,q); |
matrix.topLeftCorner< p,q >(); |
左下角p\*q |
matrix.bottomLeftCorner(p,q); |
matrix.bottomLeftCorner< p,q >(); |
右上角p\*q |
matrix.topRightCorner(p,q); |
matrix.topRightCorner< p,q >(); |
右下角p\*q |
matrix.bottomRightCorner(p,q); |
matrix.bottomRightCorner< p,q >(); |
前q行 |
matrix.topRows(q); |
matrix.topRows< q >(); |
后q行 |
matrix.bottomRows(q); |
matrix.bottomRows< q >(); |
左p列 |
matrix.leftCols(p); |
matrix.leftCols< p >(); |
右p列 |
matrix.rightCols(p); |
matrix.rightCols< p >(); |
int main(){Eigen::Matrix4f m;m << 1, 2, 3, 4,5, 6, 7, 8,9, 10,11,12,13,14,15,16;cout << "m.leftCols(2) =" << endl << m.leftCols(2) << endl << endl;cout << "m.bottomRows<2>() =" << endl << m.bottomRows<2>() << endl << endl;m.topLeftCorner(1,3) = m.bottomRightCorner(3,1).transpose();cout << "After assignment, m = " << endl << m << endl;}
输出
m.leftCols(2) =
1 2
5 6
9 10
13 14
m.bottomRows<2>() =
9 10 11 12
13 14 15 16
After assignment, m =
8 12 16 4
5 6 7 8
9 10 11 12
13 14 15 16
5. vectors的块操作
operation |
dynamic-size block |
fixed-size block |
前n个 |
vector.head(n); |
vector.head< n >(); |
后n个 |
vector.tail(n); |
vector.tail< n >(); |
i起始的n个元素 |
vector.segment(i,n); |
vector.segment< n >(i); |
Eigen(6)快操作相关推荐
- 破玩意 | 多线程 +1 的最快操作
作者 | 闪客sun 来源 | 低并发编程(ID:dibingfa) 直奔主题,多个线程,一个共享变量,不断 +1. 如果代码直接这样写,会产生线程安全问题. public class Lon ...
- eigen 列拼接_Eigen子矩阵操作
1 子矩阵操作简介 本文翻译自官方的 Using block operations.这篇文章只是我在学习的时候做的记录,可能有些陈旧了,建议直接看官方的文档. 子矩阵操作又称块操作,在矩阵运算中,子矩 ...
- Eigen的基础使用-C++
为什么80%的码农都做不了架构师?>>> #Eigen的安装 下载Eigen以后直接引用头文件即可,需要的头文件如下 Eigen支持的编译器类型 GCC, version 4. ...
- 视觉SLAM十四讲 ch3 Ubuntu18.04 KDevelop的使用及Eigen实践 入门笔记
视觉SLAM十四讲 ch3 Ubuntu18.04 KDevelop的使用及Eigen实践 入门笔记 一.创建KDevelop项目 二.编写程序 一.创建KDevelop项目 你的电脑上如果还没有安装 ...
- 【Eigen】【Eigen实践】【Eigen的使用学习记录】
[Eigen][Eigen实践][Eigen的使用学习记录] 0 前言 1 Eigen使用 1.1 头文件的使用 1.2 定义和初始化 1.2.1 定义n*m矩阵 1.2.2 定义n*1向量 1.2. ...
- clion使用Eigen
clion使用Eigen 目录 clion使用Eigen 1.下载Eigen库 2.解压-跳过 3.将Eigen文件夹添加到工程 4.修改CMakeLists.txt 5.main.cpp修改 6.编 ...
- PCL/Eigen的简单使用
*注:本文转载于以下可点开的链接.侵删,谢谢! 点云的基本数据结构 PCL学习笔记->基本用法4(使用一个矩阵转换点云) Eigen的介绍及简单使用 (详细请点链接进入) Eigen的下载与安装 ...
- Eigen 学习总结
Eigen采用源码的方式提供给用户使用,在使用时只需要包含Eigen的头文件即可进行使用.之所以采用这种方式,是因为Eigen采用模板方式实现,由于模板函数不支持分离编译,所以只能提供源码而不是动态库 ...
- Eigen: C++开源矩阵计算工具——Eigen的简单用法
Eigen非常方便矩阵操作,当然它的功能不止如此,由于本人只用到了它的矩阵相关操作,所以这里只给出了它的一些矩阵相关的简单用法,以方便快速入门.矩阵操作在算法研究过程中,非常重要,例如在图像处理中二维 ...
最新文章
- 鸿蒙开发-新建Ability与使用image-animator实现图帧动画
- SAP UI5 应用开发教程之五十八 - 使用工厂方法在运行时动态创建不同类型的列表行项目控件试读版
- Vue实战:音乐播放器(一) 页面效果
- 笨方法python3_“笨方法”学Python3,习题 43 。
- 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。
- nginx 配置upstream实现负载均衡
- Kubesploit:针对容器化环境的跨平台后渗透利用工具
- macos下刻录系统盘
- 剪贴板查看器clipbrd.exe
- 原生javascript手风琴图片切换案例
- [SPRD] 版本修改集锦
- 数据分析软件解读王者荣耀一年的“王者”成绩单
- php字符串处理之全角半角转换(正则匹配全角字符思路)
- probuilder_使用ProBuilder自定义快照原型资产
- matlab导数曲线怎样画,matlab三次样条曲线的绘制(spline和csape函数详解)
- python怎么写代码求年华收益率_python计算年收益
- [转]如何学习《离散数学》?
- DirectShow入门
- HyperLPR车牌识别库代码分析(12)
- CocosCreator + JavaScript游戏开发
热门文章
- Python3实现红黑树[上篇]
- Java并发编程实战_阿里P9整理分享的亿级流量Java高并发与网络编程实战PDF
- Ubuntu文件上锁了,怎么打开???亲测有效
- 对于计算机网络的整体框架的概括(转载)
- [渝粤教育] 重庆大学 电子商务 参考 资料
- 【渝粤教育】国家开放大学2018年秋季 1317T社会工作行政(本) 参考试题
- 【渝粤教育】 国家开放大学2020年春季 2542行政组织学 参考试题
- 【渝粤教育】电大中专学前儿童发展心理学3作业 题库
- 【渝粤教育】电大中专计算机常用工具软件 (2)作业 题库
- 【渝粤题库】陕西师范大学700005 遗传学