• 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. 在opencv3中进行图片人脸检测

    在opencv中,人脸检测用的是harr或LBP特征,分类算法用的是adaboost算法.这种算法需要提前训练大量的图片,非常耗时,因此opencv已经训练好了,把训练结果存放在一些xml文件里面.在 ...

  2. Opencv step by step - 图像融合

    两个图像的融合就是像素的融合了,其实手动操作即可,用函数操作更方便了. 下面代码的作用是融合阿狸和doctor,很和谐有木有! #include <cv.h> #include <h ...

  3. "互联网思维"背后的谎言

    互联网公司/思维是什么鬼,说来惭愧上学的时候还因为知道www(World Wide Web)的中文名自豪了好久,之后在”高等学府“里学习软件工程,还愚蠢的以为自己步入了互联网之门. internet嘛 ...

  4. Flask 开发全球化应用

    从C#世界迈入python总是令人有一种如释重负之感,同样的效果同样的功能,只需要付出1/10不到的代价,可能正是Python所倡导的简美哲学所带来的威力. 我还深深地记得在ASP.NET中做全球化的 ...

  5. WebGame开发总结

    不知不觉我们的项目开发有2年了,这两年来走了很多弯路,也收获了很多,今天在这里做一个总结. 项目基本情况: 服务器端采用c++和c#混合开发,网络层采用c++开发,业务逻辑用c#开发.客户端采用sil ...

  6. php中命名空间的使用

    简单使用 命名空间主要解决函数/类冲突的问题.由于PHP中中不允许函数重载,所以我们要使用的到命名空间的.先看一个简单的例子. <?php namespace A; public functio ...

  7. JavaScript基础---语言基础(4)

    函数,对象和数组 学习要点: 1.函数声明 2.return返回值 3.arguments对象 4.Object类型 5.Array类型 6.对象中的方法 函数是定义一次但却可以调用或执行任意多次的一 ...

  8. 第四十四课:jQuery UI和jQuery easy UI

    jQuery UI是jQuery官方提供的功能效果和UI样式.作为官方出的东西,它一直没有被人们看重,一是它没有datagrid,tree等UI库必备的东西,二是它修改太过频繁,体积庞大.其实它所有以 ...

  9. WEB前端开发规范

    WEB前端开发规范 规范目的 为提高团队协作效率, 便于后台人员添加功能及前端后期优化维护, 输出高质量的文档, 特制订此文档.本文档如有不对或者不合适的地方请及时提出, 经讨论决定后方可更改. 基本 ...

  10. 看css发现一个pointer-events:none;的东西

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...