使用Eigen的子矩阵和索引 [英] Submatrices and indices using Eigen

查看:1167
本文介绍了使用Eigen的子矩阵和索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个MATLAB项目,我想使用C ++和Eigen重新实现最重要的计算部分。
我想知道是否有一种方法来执行以下操作(MATLAB语法):

I'm currently working on a MATLAB project and I'd like to re-implement the most computational-heavy parts using C++ and Eigen. I'd like to know if there's a way to perform the following operation (MATLAB syntax):

B = A(A < 3);

对于那些不熟悉MATLAB的人,上述命令初始化一个由

For those who are not familiar with MATLAB, the above-mentioned command initializes a matrix B made of the cells in A whose values are less than 3.

我从特征论坛,可以使用以下方式获取感兴趣的指数:

I've seen from a post on the Eigen forum that it's possible to obtain the indices of interest by using:

MatrixXi indices = (A.array() < 3).cast<int>();

我想要的是:

MatrixXd B = A(A.array() < 3);

谢谢。

推荐答案

目前有一个功能请求用于选择子 - 通过在Eigen BugTracker系统中索引的矩阵。因此,我怀疑这是可能的。

There currently is a feature request for selecting sub-matrices by indexing filed at the Eigen BugTracker system. Therefore, I doubt it will be possible that way.

我想到的唯一的解决方法是手动复制数据。不太好。

The only workaround I could think of is to copy the data manually. Not very nice though.

这篇关于使用Eigen的子矩阵和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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