繁体   English   中英

c ++ armadillo cast / convert to integer type vector或matrix

[英]c++ armadillo cast/convert to integer type vector or matrix

如何double / float -typed矢量或矩阵转换为word / uword -typed矢量或矩阵


我需要创建一个索引数组indices

vec t = linspace(0, 100);
double freq = 0.25;
indices = floor(t / freq);

我在最后一行遇到了麻烦。

如果您只是处理正值,那么armadillo包的conv_to函数将与您尝试使用的方法完全相同。

vec t = linspace(0, 100);
double freq = 0.25;
ivec indices = conv_to<ivec>::from(t / freq);

如果您希望结果与使用负值t的floor函数相同,则可以用最后一行替换

ivec indices = conv_to<ivec>::from(floor(t / freq));

最好的办法是使用迭代器遍历t向量,然后将floor( *it_to_t / freq )的结果推回到索引向量上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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