Extracting and storing all 6x6 postitions from multiple resampled 6x6 matrices in an array in R
i got my answer from here . How to create a 2D vector where in like 2D array
You have two alternatives. vector of vectors or a single vector (See @Bob__'s comment).
The advantage of the vector of vectors is C++ goodness (iterator bounds checking etc). The downside is a higher cost of construction/copy. rows+1
vectors must be constructed (or copied).
The benefit of the single vector of rows*cols size is that you only require a single vector construction (or copy when needed). (Another performance benefit is cache locality of the data.)
Here's how you can preserve the [row][col] syntax.
const int rows = 6;
const int cols = 6;
vector<int> x(rows*cols);
//enable using [row][col] syntax
auto a_int = reinterpret_cast<int (*)[rows]>(x.data());
// cout << a_int[row][col] << '\n';