Say I have a 3x4x5x6 java double array a that I unroll into an ArrayList b of length 360 in the following way:
for (int i = 0; i<a.length; i++){
for (int j = 0; j<a[0].length; j++){
for (int k = 0; k<a[0][0].length; k++){
for (int m = 0; m<a[0][0][0].length; m++){
b.add(a[i][j][k][m]);
}
}
}
}
Given the index of b, is there an easy way to find the corresponding 4-tuple of indices in a?
Assuming that
bis the index on the monodimensional arrayi,j,k,mare the four resulting indices on the multidimensional arraysi,sj,sk,smare the size of any dimensionyou can use basic math, it should be something like
m = b % smk = (b / sm) % skj = (b / (sm*sk)) % sji = b / (sm*sk*sj)Basically you increment every index by one for every size of the contained arrays (by multiplying sizes) and you wrap it on its dimension.