Eigen数据类型

Eigen常用类

Eigen:Matrix,Vector,Arrays;

Matrix

        Matrix<float,Dynamic,Dynamic> <=> MatrixXf

        Matrix<float,3,3> <=> Matrix3f

#include <iostream>
#include<Eigen/Dense>
#include<string>
#include<locale>
using namespace std;
using namespace Eigen;
int main() {
    system("chcp 65001");//使用中文字符
    cout<<"---MatrixXf,Matrix3f的使用:---"<<endl;
    int rows = 5, cols = 5;
    MatrixXf m5(rows, cols);
    m5 = MatrixXf::Zero(rows,cols);
    cout<< m5<<endl;
    cout<< "---------------"<<endl;
    Matrix3f m3;
    cout<< "----初始化方法一:---"<<endl;
    m3<<1,2,3,4,5,6,7,8,9;
    cout<< m3<<endl;
    cout<< "----初始化方法二:---"<<endl;
    m3(0,0)=2;
    m3(0,1)=4;
    m3(0,2) =6;
    m3(1,0)=2;
    m3(1,1)=4;
    m3(1,2) =6;
    m3(2,0)=2;
    m3(2,1)=4;
    m3(2,2) =6;
    cout<< m3<<endl;
    cout<< "----初始化方法三:---"<<endl;
    m5 << m3,
        MatrixXf::Zero(3, cols - 3),
        MatrixXf::Zero(rows - 3, 3),
        MatrixXf::Identity(rows - 3, cols - 3);
    cout << m5<<endl;
    cout<< "----更改数组的大小:----"<<endl;
    rows =cols =6;
    m5 = MatrixXf::Zero(rows,cols);
    cout<< m5<<endl;
    cout<< "-----END-----"<<endl;
    return 0;
}

Vector

        Matrix<double,Dynamic,1> <=> VectorXd

        Matrix<float,4,1> <=> Vector4f

        Matrix<int,1,Dynamic> <=> RowVectorXi

#include <iostream>
#include<Eigen/Dense>
#include<string>
using namespace std;
using namespace Eigen;
int main() {
    system("chcp 65001");//使用中文字符
    cout << "---VectorXf,Vector2f,Vector3f,RowVectorXf,RowVector4f的使用:---" << endl;
    int rows = 4, col = 1;
    VectorXf vX(rows, col);
    vX << 1, 2, 3, 4;
    cout << vX << endl;
    cout << "---------------" << endl;
    Vector2f v21;
    v21 << 4, 5;
    cout << v21 << endl;
    cout << "---------------" << endl;
    Vector2f v22;
    v22(0, 0) = 4;
    v22(1, 0) = 4;
    cout << v22 << endl;
    cout << "---------------" << endl;
    Vector3f v31;
    v31(0, 0) = 4;
    v31(1, 0) = 4;
    v31(2, 0) = 4;
    cout << v31 << endl;
    cout << "---------------" << endl;
    v31 << 67, 2, 1;
    cout << v31 << endl;
    cout << "---------------" << endl;

    RowVectorXf rvX(col, rows + 3);
    rvX << 1, 2, 3, 4, 6, 8, 9;
    cout << rvX << endl;
    cout << "---------------" << endl;
    rvX(0, 0) = 90;
    rvX(0, 1) = 78;
    rvX(0, 2) = 1;
    rvX(0, 3) = 2;
    rvX(0, 4) = -1;
    rvX(0, 5) = 34;
    rvX(0, 6) = 2;
    cout << rvX << endl;
    cout << "---------------" << endl;

    RowVector4f v41;
    v41 << 1, 2, 3, 4;
    cout << v41 << endl;
    cout << "---------------" << endl;

    v41(0, 0) = 1;
    v41(0, 1) = 4;
    v41(0, 2) = 5;
    v41(0, 3) = 6;
    cout << v41 << endl;
    cout << "---------------" << endl;




    return 0;
}

Arrays

        Array<float,Dynamic,Dynamic> <=> ArrayXXf

        Array<double,Dynamic,1> <=> ArrayXd

        Array<int,1,Dynamic> <=> RowArrayXi

        Array<float,3,3> <=> Array33f

        Array<float,4,1> <=> Array4f

#include<Eigen/Dense>
#include<iostream>
using namespace std;
using namespace Eigen;
int main()
{
    
    system("chcp 65001");//使用中文字符
    cout<<"---ArrayXXf,ArrayXf,Array22f的使用:---"<<endl;
    int rows = 6,cols =1;
    ArrayXXf v32(rows-3,cols+1);
    v32<<1,2,3,4,5,6;
    cout<<v32<<endl;
    cout << "---------------" << endl;
    v32(0,0)=23;
    v32(0,1)=24;
    v32(1,0)=26;
    v32(1,1)=26;
    v32(2,0)=26;
    v32(2,1)=26;
    cout<<v32<<endl;
    cout << "---------------" << endl;
    ArrayXf v6(rows,cols);
    v6<<1,2,3,4,5,6;
    cout<<v6<<endl;
    cout << "---------------" << endl;
    ArrayXf v4{{1},{1},{1},{4}};
    cout<<v4<<endl;
    cout << "---------------" << endl;
    ArrayXXf v14(1,4);
    v14<<1,2,3,4;
    cout<<v14<<endl;
    cout << "---------------" << endl;
    Array22f v22{{2,3},{1,5}};
    cout<<v22<<endl;
    cout << "---------------" << endl;
    v22<<2,2,4,5;
    cout<<v22<<endl;
    cout << "---------------" << endl;
    v22(0,0)=23;
    v22(0,1)=24;
    v22(1,0)=26;
    v22(1,1)=26;
    cout<<v22<<endl;
    cout << "---------------" << endl;
    Array2f v2(1,2);
    cout<<v2<<endl;
    cout << "---------------" << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值