Index A Matrix Using A Vector of Indices in Armadillo LIbrary

帅比萌擦擦* 提交于 2019-12-11 06:25:46

问题


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?


回答1:


One way to do it is

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


来源:https://stackoverflow.com/questions/46276477/index-a-matrix-using-a-vector-of-indices-in-armadillo-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!