使用 Armadillo 库中的索引向量索引矩阵

Index A Matrix Using A Vector of Indices in Armadillo LIbrary

我正在使用矩阵代数的 Armadillo Cpp 代码。我有一个特征向量矩阵 E,我想按向量 d.

中的特征值对其进行排序
mat E;
vec d;
eig_sym(d,E,Rxx);


// Sort indices of eignen values / vectors
// based on decreasing real part of eigen values.
uvec order = sort_index(-d);

// Extract top eigen vectors.
E = E(span::all,order(1,nb_sources));

我在文档中找不到与这种索引相关的任何内容。使用向量进行索引是一个非常普遍的要求,如果 Armadillo 中没有它,我会感到很惊讶。

在 Armadillo 中执行此操作的正确方法是什么?

一种方法是

E = E.cols(order(span(0,nb_sources-1)));