• 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
  • Usage as temporary objects
 

 
  1. The comma initializer
    1. a simple example 

      m << 1, 2, 3,
      4, 5, 6,
      7, 8, 9;
      std::cout << m;
    2. 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
        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
  2. Special metrics and arrays
    1. 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 0

        A one-dimensional dynamic-size array:
        0
        0
        0

        A two-dimensional dynamic-size array:
        0 0 0 0
        0 0 0 0
        0 0 0 0

    2. Constant(rows,cols,value);
    3. Identity();
    4. 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
    5. 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

       

  3. Usage as temporary objects
    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

The finished() method is necessary here to get the actual matrix object once the comma initialization of our temporary submatrix is done.

C++_Eigen函数库用法笔记——Advanced Initialization的更多相关文章

  1. C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations

    The advantages of Array Addition and subtraction Array multiplication abs() & sqrt() Converting ...

  2. 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 ...

  3. C++_Eigen函数库用法笔记——Matrix and Vector Arithmetic

    Addition and subtraction Scalar multiplication and division Transposition Matrix-matrix and matrix-v ...

  4. PHP中正则替换函数preg_replace用法笔记

    今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. 转: ES6异步编程: co函数库的含义与用法

    转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...

  7. makefile笔记10 - makefile 函数库文件

    函数库文件也就是对 Object 文件(程序编译的中间文件)的打包文件.在 Unix 下,一般是由命令"ar"来完成打包工作. 一.函数库文件的成员 一个函数库文件由多个文件组成. ...

  8. OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法

    函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...

  9. python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法

    python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...

随机推荐

  1. Java开发环境的搭建

    确定自己的操作系统版本并下载安装JDK 1.下载JDK windows系统: 右键我的电脑->属性;如下图: 2.下载JDK 下载地址:http://www.oracle.com/index.h ...

  2. flask 使用 SQLAlchemy 的两种方式

    1. 使用 flask-SQLAlchemy 扩展 # flask-ext-sqlalchemy.py from flask import Flask from flask.ext.sqlalchem ...

  3. android 6.0(api 23) SDK,不再提供org.apache.http.*(只保留几个类)

    在使用android-async-http的时候我的apl 更新到了23,我的build version也是23的时候出现了,org.apache.http.Header这个类找不到的情况,原因是在a ...

  4. iOS——数据安全性问题小结

    在移动互联网快速发展的今天,iOS应用直接运行在用户的手机上,与运行在服务器后台服务相比,更有可能被黑客攻击. a.网络安全: 1.1 安全地传输用户密码 事先生成一对用于加密的公私钥,客户端登录的时 ...

  5. Quartz.NET syudy

    Quartz.NET   Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它 ...

  6. Thrift搭建分布式微服务(一)

    一.Thrift是什么? 关于Thrift的基本介绍,参看张善友的文章Thrift简介. 二.为什么使用微服务? 在公司的高速发展过程中,随着业务的增长,子系统越来越多.各系统间又不同程度的在某些逻辑 ...

  7. Asp.Net的两种开发方式

    来源:http://www.zhidao91.com/asp-net/ 在经过对.Net平台深入的学习以后,我发现很多语言开发动态网站时,它的后台逻辑都差不多是相同的,今天在这里我给大家来聊聊在.Ne ...

  8. WDCP安装并配置php5.4和mongodb

    记录一下,免得忘了.全部都是自己测试用过的安装过程没有问题. linux常用命令 mv 移动文件 mkdir 创建文件夹 rm 删除 cp 复制 netstat 网络状态 tar 解压 wget 下载 ...

  9. CSS 外边距合并

    外边距合并指的是,当两个垂直外边距相遇时,它们将形成一个外边距. 合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者. 外边距合并 外边距合并(叠加)是一个相当简单的概念.但是,在实践中对网 ...

  10. 云计算之路-阿里云上:Wireshark抓包分析一个耗时20秒的请求

    这篇博文分享的是我们针对一个耗时20秒的请求,用Wireshark进行抓包分析的过程. 请求的流程是这样的:客户端浏览器 -> SLB(负载均衡) -> ECS(云服务器) -> S ...