C++_Eigen函数库用法笔记——Advanced Initialization
- The comma initializer
- a simple example
- join and block initialize
- join two row vectors together
- initialize metrics with block structure
- fill block expression
- Special metrics and arrays
- Zero();
- Array33f::Zero();
- ArrayXf::Zero(3);
- ArrayXXf::Zero(3,4);
- Constant(rows,cols,value);
- Identity();
- LinSpaced
- 3 ways to construct the matrix
- Zero();
- Usage as temporary objects
- The comma initializer
- a simple example
Matrix3f m;m << 1, 2, 3,4, 5, 6,7, 8, 9;std::cout << m;
- join and block initialize
- join two row vectors together
RowVectorXd vec1(3);vec1 << 1, 2, 3;std::cout << "vec1 = " << vec1 << std::endl;RowVectorXd vec2(4);vec2 << 1, 4, 9, 16;;std::cout << "vec2 = " << vec2 << std::endl;RowVectorXd joined(7);joined << vec1, vec2;std::cout << "joined = " << joined << std::endl;vec1 = 1 2 3
vec2 = 1 4 9 16
joined = 1 2 3 1 4 9 16 - initialize metrics with block structure
MatrixXf matA(2, 2);matA << 1, 2, 3, 4;MatrixXf matB(4, 4);matB << matA, matA/10, matA/10, matA;std::cout << matB << std::endl;1 2 0.1 0.2
3 4 0.3 0.4
0.1 0.2 1 2
0.3 0.4 3 4 - fill block expression
Matrix3f m;m.row(0) << 1, 2, 3;m.block(1,0,2,2) << 4, 5, 7, 8;m.col(2).tail(2) << 6, 9;std::cout << m;1 2 3
4 5 6
7 8 9
- join two row vectors together
- a simple example
- Special metrics and arrays
- Zero()
- Array33f::Zero();
- ArrayXf::Zero(3);
- ArrayXXf::Zero(3,4);
std::cout << "A fixed-size array:\n";Array33f a1 = Array33f::Zero();std::cout << a1 << "\n\n";std::cout << "A one-dimensional dynamic-size array:\n";ArrayXf a2 = ArrayXf::Zero(3);std::cout << a2 << "\n\n";std::cout << "A two-dimensional dynamic-size array:\n";ArrayXXf a3 = ArrayXXf::Zero(3, 4);std::cout << a3 << "\n";A fixed-size array:
0 0 0
0 0 0
0 0 0A one-dimensional dynamic-size array:
0
0
0A two-dimensional dynamic-size array:
0 0 0 0
0 0 0 0
0 0 0 0
- Constant(rows,cols,value);
- Identity();
- LinSpaced
ArrayXXf table(10, 4);table.col(0) = ArrayXf::LinSpaced(10, 0, 90);table.col(1) = M_PI / 180 * table.col(0);table.col(2) = table.col(1).sin();table.col(3) = table.col(1).cos();std::cout << " Degrees Radians Sine Cosine\n";std::cout << table << std::endl;Degrees Radians Sine Cosine
0 0 0 1
10 0.175 0.174 0.985
20 0.349 0.342 0.94
30 0.524 0.5 0.866
40 0.698 0.643 0.766
50 0.873 0.766 0.643
60 1.05 0.866 0.5
70 1.22 0.94 0.342
80 1.4 0.985 0.174
90 1.57 1 -4.37e-08 - 3 ways to construct the matrix
const int size = 6;MatrixXd mat1(size, size);mat1.topLeftCorner(size/2, size/2) = MatrixXd::Zero(size/2, size/2);mat1.topRightCorner(size/2, size/2) = MatrixXd::Identity(size/2, size/2);mat1.bottomLeftCorner(size/2, size/2) = MatrixXd::Identity(size/2, size/2);mat1.bottomRightCorner(size/2, size/2) = MatrixXd::Zero(size/2, size/2);std::cout << mat1 << std::endl << std::endl;MatrixXd mat2(size, size);mat2.topLeftCorner(size/2, size/2).setZero();mat2.topRightCorner(size/2, size/2).setIdentity();mat2.bottomLeftCorner(size/2, size/2).setIdentity();mat2.bottomRightCorner(size/2, size/2).setZero();std::cout << mat2 << std::endl << std::endl;MatrixXd mat3(size, size);mat3 << MatrixXd::Zero(size/2, size/2), MatrixXd::Identity(size/2, size/2),MatrixXd::Identity(size/2, size/2), MatrixXd::Zero(size/2, size/2);std::cout << mat3 << std::endl;
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
- Zero()
- Usage as temporary objects
MatrixXf mat = MatrixXf::Random(2, 3);std::cout << mat << std::endl << std::endl;mat = (MatrixXf(2,2) << 0, 1, 1, 0).finished() * mat;std::cout << mat << std::endl;0.68 0.566 0.823
-0.211 0.597 -0.605-0.211 0.597 -0.605
0.68 0.566 0.823
C++_Eigen函数库用法笔记——Advanced Initialization的更多相关文章
- C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations
The advantages of Array Addition and subtraction Array multiplication abs() & sqrt() Converting ...
- C++_Eigen函数库用法笔记——Block Operations
Using block operations rvalue, i.e. it was only read from lvalues, i.e. you can assign to a block Co ...
- C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic
Addition and subtraction Scalar multiplication and division Transposition Matrix-matrix and matrix-v ...
- PHP中正则替换函数preg_replace用法笔记
今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
- 转: ES6异步编程: co函数库的含义与用法
转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...
- makefile笔记10 - makefile 函数库文件
函数库文件也就是对 Object 文件(程序编译的中间文件)的打包文件.在 Unix 下,一般是由命令"ar"来完成打包工作. 一.函数库文件的成员 一个函数库文件由多个文件组成. ...
- OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法
函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...
- python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法
python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...
随机推荐
- 从Swift学习iOS开发的路线指引
本文主要是楼主近段时间从Swift语法开始自学iOS开发的流程总结,PS 一个前提,楼主的生存环境中买不到一本iOS开发中文教程,所以基本都是百度摸索出来的 >_< 主要流程 学习Swif ...
- jquery-ajax-async之浏览器差异
最近的PC项目遇到了一个问题,日志记录程序会在1s内多次发起对首页的请求,一时间没有找到原因. 简单描述一下问题:访问一个首页的时候,由于代码质量不高的原因,访问就连接数据库,但是同时存在的问题是一秒 ...
- ThinkPHP之验证码的使用
ThinkPHP中已经提供了验证码的生成以及验证的功能.下面介绍如何使用验证码.编程的时候还是采用MVC的方式 View层 <!DOCTYPE html> <html> < ...
- ArrayAdapter与SimpleAdapter的使用
在使用ListView中我们使用到adapter,android中为我们不仅提供了BaseAdapter类来让我们自定义自己的Adapter,还为我们提供了ArrayAdapter以及SimpleAd ...
- linux用户管理命令
关键字 useradd passwd who w uptime 1.useradd添加用户命令 useradd 用户名 passwd 用户名 (设置密码) 2.userdel 删除用户 userdel ...
- c# 6.0新特性(二)
写在前面 上篇文章介绍了c#6.0的using static,Auto Property Initializers,Index Initializers新的特性,这篇文章将把剩下的几个学习一下. 原文 ...
- 每天一个linux命令(18):find 命令概览
Linux 下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所 以它的选项也很多,其中大部分选项都值得我们 ...
- 如何在VMWare Workstation实现虚拟机与真机的文件共享
1.进入虚拟机的配置选项 进入方法有三种,一种是使用快捷键Ctrl+D,第二种是先右键点击虚拟机再选择Settings选项,第三种是点击快捷栏中的VM后选择Settings选项,后两种方法的截图如下. ...
- Android的开发环境的发展演变
1.Android的开发环境: 之前大家都是安装eclipse,然后再下载安装sdk等插件,还需要配置比较麻烦.不过2013年,有了新的选择,在I/O大会上,谷歌推出新的Android开发环境——An ...
- KK录像机破解补丁
KK录像机是由杭州凯凯科技有限公司出品的免费的集游戏录像.视频录制.视频剪辑.添加字幕.添加音乐等功能于一体的高清视频录制软件.操作简单,且兼容录制所有游戏视频,是玩家分享精彩的工具. KK VIP功 ...