本征中的十进制矢量
Decimate vector in eigen
本文关键字:十进制 更新时间:2023-10-16
我有一个浮点数组Eigen::ArrayXf,我需要对其进行抽取(即从f.I.8个样本中挑选1个)。
Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0, Eigen::InnerStride<8> >(signal.data(), length, 1).eval();
这是有效的,但需要注意:我需要知道长度有多长,而且它可能被指定得太长,从而导致运行时错误。
Q: 有没有一种方法可以抽取所有可能的值,使结果长度为==signal.size()/8?
两件事。您正在使用c'tor来映射矩阵:
Map(PointerArgType数据Ptr,索引nbRows,索引nbCols,const StrideType&a_sarde=跨步类型())
动态大小矩阵情况下的构造函数。
参数
dataPtr pointer to the array to map nbRows the number of rows of the matrix expression nbCols the number of columns of the matrix expression a_stride optional Stride object, passing the strides.
我想你想要向量的c'tor:
映射(PointerArgType dataPtr,索引a_size,const StrideType&a_sarde=跨步类型())
构造函数。
参数
dataPtr pointer to the array to map a_size the size of the vector expression a_stride optional Stride object, passing the strides.
第二件事是您想要length == signal.size())/8
。这总是一个整数吗?还是你在四舍五入?如果数据长度为16,并且您想要位置[0]
和[8]
,则使用1+(signal.size()-1)/8
作为长度参数:
Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0, Eigen::InnerStride<8> >(signal.data(), 1+((signal.size()-1)/8) ).eval();
例如:
#include <Eigen/Core>
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
Eigen::VectorXf signal;
signal.setLinSpaced(64, 0.0, 63.);
cout << "Original signal:" << endl << signal.transpose() << endl;
Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0,
Eigen::InnerStride<8> >(signal.data(), 1+((signal.size()-1)/8)).eval();
cout << endl << "Decimated:" << endl << decimatedSignal.transpose() << endl;
return 0;
}
输出
原始信号:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 20 21 23 24 25 26 28 29 30 32 33 34 35 36 37 39 41 43 44 46 47 48 49 50 51 52 53 54 56 57 58 60 61 62 63
小数:0 8 16 24 32 40 48 56
我认为这正是你想要的。
相关文章:
- visual在c++中将十进制数转换为二进制数
- C++十进制到二进制,如何转换
- 计算十进制 c++ 之后的数字
- C++从二进制转换为十进制数
- 有没有办法通过使用十进制 ASCII 代码自动类型扣除来获取字符?
- 为什么有时我输入一个整数,程序将第一个输入的数字打印成十进制数?
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- cin 的十进制输入验证?
- 我编写了代码将十进制分数转换为其二进制等效数.它编译得很好,但在执行时挂起
- 将分数转换为十进制数并对其进行排序
- uint8_t同一二进制文件的不同十进制值
- 如何打印大于"无符号长长"的"std::bitset"的十进制值?
- 调用方如何知道 VARIANT 中何时有十进制?
- 将字符串(可以是十进制字符串或十六进制字符串)转换为整数C++
- 十进制到二进制转换器 c++
- 使用标准库计算字符串中的十进制数
- 如何在C ++中将二进制字符串128位转换为十进制字符串?
- 如何计算整数的十进制数字?
- (第 1 位 + 第 2 位)以十进制数表示
- 在 C++ 中使用带有十六进制十进制和八进制数的 unsetf