C ++ Armadillo生成给定vec或矩阵的索引uvec,而无需循环它 [英] C++ Armadillo Generate Indices uvec of a given vec or matrix without looping it
问题描述
Hellos伙计们,
Hellos guys,
我的问题可能很明显,但是我没有在其他帖子或《犰狳文档》上找到答案.
My question might be obvious but i didn't find answers on other posts or Armadillo Doc.
我想创建一个向量B(在我的情况下为arma :: uvec),并使用给定向量A的每个索引.因此所需元素为(0:A.n_elem-1 ).我可以循环播放,但是我需要最佳地优化时间,所以我只想知道是否可以不循环播放.最后一点,我想避免使用C ++ 11.
I would like to create a vector B(arma::uvec in my case), with every index of a given vector A. So the needed elements are (0:A.n_elem-1). I could loop it, but I need to optimize time at its best, so I just want to know if I can generate it without looping it. Last point, I would like to avoid C++ 11.
谢谢您的时间.
我确实使用过find_finite(X)来生成索引vec,因为我的数据都是有限的,我仍然不知道正确的方法.
EDIT 1 : I did use find_finite(X), to generate my indices vec, because my datas are all finite, i still don't know the proper way to do it.
推荐答案
我不太了解with every index of a given vector A
,但是如果您需要B
来包含0:A.n_elem-1
,则可以执行以下操作:
I don't quite understand with every index of a given vector A
, but if you need B
to contain 0:A.n_elem-1
, you can do:
vec B = regspace<vec>(0, A.n_elem-1)
上面的代码等效于MATLAB中的B = 0:length(A)-1
.
Above code is equivalent to B = 0:length(A)-1
, in MATLAB.
希望有帮助.
这篇关于C ++ Armadillo生成给定vec或矩阵的索引uvec,而无需循环它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!