简体   繁体   中英

Index A Matrix Using A Vector of Indices in Armadillo LIbrary

I'm using the Armadillo Cpp code for matrix algebra. I have an Eigenvector matrix E that I want to sort by its eigenvalues in a vector 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));

I couldn't find anything related to this kind of indexing in the documentation. Indexing using a vector is such a common requirement that I'd be surprised if it isn't present in Armadillo.

What is the proper way to do this in Armadillo?

一种方法是

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM