如何复制特征矩阵 [英] How to copy Eigen matrix

查看:100
本文介绍了如何复制特征矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Eigen::MatrixXd,它们总是只有一行.输入矩阵为A,我想将此矩阵复制到另一个矩阵B,但是矩阵之间的列数可以不同.

I have two Eigen::MatrixXd and they always have a single row. The input matrix is A and I want to copy this matrix into another matrix B, but the number of columns between the matrices can be different.

以下是一个示例:

A
 0.5

我需要创建一个1行4列的B矩阵,这样它将是:

And I need to create a B matrix of 1 rows and 4 columns, so that it will be:

B
 0.5 0.5 0.5 0.5

但是如果A是:

A
 1 0.5

然后B将是

B
 1 0.5 1 0.5

我该怎么办?

推荐答案

您可以使用(等待)replicate函数复制矩阵.第一个参数是重复行的次数,第二个参数是重复列的次数.

You can replicate a matrix by using the (wait for it) replicate function. The first parameter is how many times to repeat the rows, the second is the number of times to repeat the columns.

#include <iostream>
#include <Eigen/Core>

int main()
{
    Eigen::MatrixXd a(1, 2), b;
    a << 1, 0.5;
    b = a.replicate(1, 2);
    std::cout << a << "\nbecomes:\n" << b << std::endl;

    return 0;
}

给予

1 0.5
变为:
1 0.5 1 0.5

1 0.5
becomes:
1 0.5 1 0.5

这篇关于如何复制特征矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆