c++ - 在 Armadillo 中不复制数据的滑动窗口

标签 c++ armadillo

假设我有如下所示的大型 Armadillo 矩阵:

9 4 8 6 7 ...
5 1 9 4 5 ...
6 6 4 1 2 ...

我想用一个宽度为 3 的小窗口滑过这个大矩阵,例如

9 4 8
5 1 9
6 6 4

4 8 6
1 9 4
6 4 1

8 6 7
9 4 5
4 1 2

...

但我不想将这些数据复制到新矩阵,而是 我想重用 RAM 中已经存在的信息。 有办法吗?

最佳答案

您可以尝试以下操作,使用 submat ,创建子矩阵 View :

using namespace arma;
const unsigned total_rows = 10;
const unsigned total_cols = 10;

mat all_data(total_rows, total_cols);
// fill your data here
// ...

const unsigned window_rows = 3;
const unsigned window_cols = 3;

const auto num_windows_w = total_cols - window_cols;
const auto num_windows_h = total_rows - window_rows;
for (unsigned row_start = 0; row_start < num_windows_h; ++row_start) {
  for (unsigned col_start = 0; col_start < num_windows_w; ++col_start) {
    auto window = all_data.submat(row_start, col_start, row_start + window_rows, col_start + window_cols);
    // process your window here
    //...
  }
}

您还可以使用 mat::span 执行相同类型的操作。

关于c++ - 在 Armadillo 中不复制数据的滑动窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22638308/

相关文章:

c++ - node.js 附加组件中未捕获异常

c++ - Armadillo C++ : Sorting a vector in terms of two other vectors

c++ - Armadillo 中 SpMat<Type> 的迭代器是否只访问非零条目?

c++ - 使用模板还是 void?

c++ - 在C++中向数组添加索引和指定数字

c++ - 使用 SFML 和 Qt

C++ 在模板声明中使用默认值

c++ - 在 MFC 中捕获消息 - 有什么区别?

c++ - Armadillo 库中的 sort_index() 函数给出了错误的结果

armadillo - Armadillo 如何摆脱错误信息