The question is quite straightforward. After some trials, here is the most efficient code I found:
//For the sake of the example, I initialize every entry as zero.
vector<float> vector1D(1024 * 768, 0);
vector<vector<float>> vector2D(768, vector<float>(1024,0));
int counter = 0;
for (int i = 0; i < 768; i++) {
for (int j = 0; j < 1024; j++) {
vector2D[i][j] = vector1D[counter++];
}
}
Is there a faster way?