Eigen库

Stella981
• 阅读 956

MatrixXd表示任意size的矩阵,元素类型为double; VectorXd表示任意size的向量,元素类型为double.

//创建3*1的向量v,并赋值为1,2,3
VectorXd v(3);
v << 1, 2, 3;

使用固定尺寸的Matrix,Vector相比于可变尺寸的Matrix,Vector,例如Matrix3d m代替MatrixXd m(3,3)有以下优点:

运行速度更快,编译期间可实现更严格的错误检查。

Eigen中,所有的矩阵,向量都是Matrix模板类的对象,向量只是矩阵的特例,行数或者列数为1.

//便捷定义
typedef Matrix<float, 4, 4> Matrix4f;
typedef Matrix<float, 3, 1> Vector3f;
typedef Matrix<int, 1, 2> RowVector2i;

typedef Matrix<double, Dynamic, Dynamic> MatrixXd;  //编译期未知尺寸

 Eigen中通过()获取其元素,起始索引为0。The operator[] is also overloaded for index-based access in vectors, but keep in mind that C++ doesn't allow operator[] to take more than one argument.

Eigen库

 transpose()计算矩阵的转置, transpose()不支持就地转置,使用transposeInPlace()来实现就地转置。

 Array

We adopt the convention that typedefs of the form ArrayNt stand for 1-dimensional arrays, where N and t are the size and the scalar type.For 2-dimensional arrays, we use typedefs of the form ArrayNNt. 

Eigen库

matrix和array之间可以相互进行转换,通过调用matrix的.array()函数将matrix转换为array表达式;通过调用array的.matrix()函数将array转换为matrix表达式。

Eigen中禁止一个表达式中混合使用matrix和array,但允许赋值运算符这样操作。

Eigen中为matrix提供了cwiseProduct()函数以实现逐元素相乘。

 Block Operation

Eigen库

matrix.row(i) 获取矩阵matrix的第i行,matrix.col(j)获取矩阵matrix的第j列。相比于使用block()性能更好。

Eigen also provides special methods for blocks that are flushed against one of the corners or sides of a matrix or array. For instance, .topLeftCorner() can be used to refer to a block in the top-left corner of a matrix.

Eigen库

Eigen库

squaredNorm() 计算2范数的平方,norm()计算2范数,lpNorm

()计算p范数,p设置为Infinity可计算无穷范数。

The following reductions operate on boolean values:

  • all() returns true if all of the coefficients in a given Matrix or Array evaluate to true .
  • any() returns true if at least one of the coefficients in a given Matrix or Array evaluates to true .
  • count() returns the number of coefficients in a given Matrix or Array that evaluate to true.

 Visitors

Visitors are useful when one wants to obtain the location of a coefficient inside a Matrix or Array. The simplest examples are maxCoeff(&x,&y) and minCoeff(&x,&y), which can be used to find the location of the greatest or smallest coefficient in a Matrix or Array.

The arguments passed to a visitor are pointers to the variables where the row and column position are to be stored. These variables should be of type Index

Eigen库

 matrix.data()函数返回一个指向矩阵内存地址的指针。Eigen中矩阵默认以column-major存储元素值。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
2年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Java修道之路,问鼎巅峰,我辈代码修仙法力齐天
<center<fontcolor00FF7Fsize5face"黑体"代码尽头谁为峰,一见秃头道成空。</font<center<fontcolor00FF00size5face"黑体"编程修真路破折,一步一劫渡飞升。</font众所周知,编程修真有八大境界:1.Javase练气筑基2.数据库结丹3.web前端元婴4.Jav
Stella981 Stella981
2年前
Rust编程基础:016、vector
1、创建空的vector:Vec<Tletmutv:Vec<i32Vec::new();//v.push(1);2、创建包含初始值的vectorletvvec!1,2,3;3、丢弃vector{letv1vec!1,2,3;}
Stella981 Stella981
2年前
C++ STL Vector
前言vector,是C中的向量,也可以把他理解成为一个可变数组。熟练的应用好vector,可以提高算法设计的速度。在使用vector前,请先添加头文件。include<vectorvector的初始化vector<inta(10);//创建一个含是个元素的向量,元素值未知
Wesley13 Wesley13
2年前
Oracle一张表中实现对一个字段不同值和总值的统计(多个count)
需求:统计WAIT\_ORDER表中的工单总数、未处理工单总数、已完成工单总数、未完成工单总数。表结构:为了举例子方便,WAIT\_ORDER表只有两个字段,分别是ID、STATUS,其中STATUS为工单的状态。1表示未处理,2表示已完成,3表示未完成总数。 SQL:  1.SELECT   2
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Stella981 Stella981
2年前
C++vector,stack,queue,deque, list基本使用
vector初始化  (1)vector<inta(10);//定义了10个整型元素的向量(尖括号中为元素类型名,它可以是任何合法的数据类型),但没有给出初值,其值是不确定的。  (2)vector<inta(10,1);//定义了10个整型元素的向量,且给出每个元素的初值为1  (3)vector
Python进阶者 Python进阶者
2个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这