Index A Matrix Using A Vector of Indices in Armadillo LIbrary
Asked Answered
E

1

2

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?

Exotoxin answered 18/9, 2017 at 9:57 Comment(0)
F
3

One way to do it is

E = E.cols(order(span(0,nb_sources-1)));
Feeling answered 18/9, 2017 at 10:59 Comment(2)
Thanks! this does the job. How can I perform this type of indexing in both dimesnions?Exotoxin
See 'non-contiguous views' at arma.sourceforge.net/docs.html#submatFeeling

© 2022 - 2024 — McMap. All rights reserved.