假设我有如下所示的大型 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/