在犰狳图书馆中使用索引向量对矩阵进行索引 [英] Index A Matrix Using A Vector of Indices in Armadillo LIbrary

查看:108
本文介绍了在犰狳图书馆中使用索引向量对矩阵进行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Armadillo Cpp代码用于矩阵代数.我有一个特征向量矩阵E,我想按其特征值在向量d中进行排序.

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));

我在文档中找不到与这种索引相关的任何内容.使用向量进行索引是一个常见的要求,如果Armadillo中不存在索引,我会感到惊讶.

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)));

这篇关于在犰狳图书馆中使用索引向量对矩阵进行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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