• The advantages of Array
  • Addition and subtraction
  • Array multiplication
  • abs() & sqrt()
  • Converting between array and matrix expressions
 

 
  • The advantage of Array
    • provides an easy way to perform coefficient-wise operations, such as adding a constant to every coefficient in the array or multiplying two arrays coefficient-wise
 
  • Addition and subtraction
int main()
{
ArrayXXf a(3,3);
a << 1,2,3,
  4,5,6,
  7,8,9;
cout << “a - 2 = “ <<endl << a - 2 << endl;
}
 
a - 2 = 
-1  0  1
 2  3  4

 5  6  7
 
  • Array multiplication
    • array multiply array, arrays interpret multiplication as coefficient-wise product.
    • two arrays can be multiplied if and only if they have the same dimensions.
int main()
{
ArrayXXf a(2,2);
ArrayXXf b(2,2);
a << 1,2,
3,4;
b << 5,6,
7,8;
cout << "a * b = " << endl << a * b << endl;
 
a * b = 

 5 12

21 32
  • abs() & sqrt()
    • the .abs()method takes the absolute value of each coefficient
    • the .sqrt()computes the square root of the coefficients
int main()
{
ArrayXf a = ArrayXf::Random(5);
a *= 2;
cout << "a =" << endl
<< a << endl;
cout << "a.abs() =" << endl
<< a.abs() << endl;
cout << "a.abs().sqrt() =" << endl
<< a.abs().sqrt() << endl;
cout << "a.min(a.abs().sqrt()) =" << endl
<< a.min(a.abs().sqrt()) << endl;
a =
  1.36
-0.422
  1.13
  1.19
  1.65
a.abs() =
 1.36
0.422
 1.13
 1.19
 1.65
a.abs().sqrt() =
1.17
0.65
1.06
1.09
1.28
 
  • Converting between array and matrix expressions
    • Mixing matrices and arrays in an expression is forbidden
int main()
{
MatrixXf m(2,2);
MatrixXf n(2,2);
MatrixXf result(2,2);
m << 1,2,
3,4;
n << 5,6,
7,8;
result = m * n;
cout << "-- Matrix m*n: --" << endl << result << endl << endl;
result = m.array() * n.array();
cout << "-- Array m*n: --" << endl << result << endl << endl;
result = m.cwiseProduct(n);
-- Matrix m*n: --
19 22
43 50

-- Array m*n: --
 5 12
21 32

 
 
Here is a more advanced example

int main()
{
MatrixXf m(2,2);
MatrixXf n(2,2);
MatrixXf result(2,2);
m << 1,2,
3,4;
n << 5,6,
7,8;
result = (m.array() + 4).matrix() * m;
cout << "-- Combination 1: --" << endl << result << endl << endl;
result = (m.array() * n.array()).matrix() * m;
cout << "-- Combination 2: --" << endl << result << endl << endl;

-- Combination 1: --
23 34
31 46

-- Combination 2: --
 41  58
117 170

 
 
 
 

C++_Eigen函数库用法笔记——The Array class and Coefficient-wise operations的更多相关文章

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

  2. C++_Eigen函数库用法笔记——Advanced Initialization

    The comma initializer a simple example  join and block initialize  join two row vectors together ini ...

  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. Array.fill()函数的用法

    ES6,Array.fill()函数的用法   ES6为Array增加了fill()函数,使用制定的元素填充数组,其实就是用默认内容初始化数组. 该函数有三个参数. arr.fill(value, s ...

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

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

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

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

  8. PHP移动互联网开发笔记(5)——基础函数库

    一.数学函数库 ● floor 舍一取整(向下取整) float floor (float $value); <?php echo(floor(0.60)."<br>&qu ...

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

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

随机推荐

  1. Response.Redirect("x.aspx);跳转后session为null的解决方法

    通常我们做登陆的时候都是登录成功后为管理员保存一些信息,一般都会写类似下面的代码 if(登录成功) { Session["xx"] = "user"; Resp ...

  2. Java系列: 我的第一个spring aop练习

    看<Spring in action>有一段时间了,陆续也都看懂了,但是看懂和自己动手写确实是两回事,今天花了几个小时陆续开始安装spring,开始使用DI,然后使用AOP,在写AOP例子 ...

  3. 8.HBase In Action 第一章-HBase简介(1.2.2 捕获增量数据)

    Data often trickles in and is added to an existing data store for further usage, such as analytics, ...

  4. Spring的BeanPostProcesser接口介绍

    前言 废话不多说,直接进入主题. 同学们有想过这么一种情况吗:Spring容器提供给我们的一些接口实现类并不能满足我们的要求,但是我们又不想重新写一个类,只想在原来类上修改一些属性? 举个例子,Spr ...

  5. Mustache.js前端模板引擎源码解读

    mustache是一个很轻的前端模板引擎,因为之前接手的项目用了这个模板引擎,自己就也继续用了一会觉得还不错,最近项目相对没那么忙,于是就抽了点时间看了一下这个的源码.源码很少,也就只有六百多行,所以 ...

  6. OWIN-WebAPI-Windows Service

    tks: https://github.com/danesparza/OWIN-WebAPI-Service add 2015 0717:http://kb.cnblogs.com/page/5092 ...

  7. JavaScript、CSS、JSP 实现用户注册页面与信息校验

    参考:http://blog.csdn.net/fightfaith/article/details/50277337 需求:实现用户注册页面并作出逻辑校验.要求: (1)完成注册页面样式如下: (2 ...

  8. Oracle写函数读写日志实例

    1.用DBA登录赋权限create or replace directory D_OUTPUT as 'D:\TEMP'; grant read,write on directory D_OUTPUT ...

  9. 洛谷P1121 环状最大两段子段和

    题目描述 给出一段环状序列,即认为A[1]和A[N]是相邻的,选出其中连续不重叠且非空的两段使得这两段和最大. 输入输出格式 输入格式: 输入文件maxsum2.in的第一行是一个正整数N,表示了序列 ...

  10. POJ1065 Area

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18499   Accepted: 5094 Description You ...