How can we convert 3D array to 1D array in java??
I used the code bellow:
input :double [][][]S_p = { { { 1.1, 2.1 }, { 3.2, 4.1 } },
{ { 5.2, 6.1 }, { 7.1, 8.3 } } };
int rows = S_p.length;
int columns = S_p[0].length;
int depth = S_p[0][0].length;
double [] d1 = new double[row*columns*depth];
for(int i=0;i<depth;i++) {
for(int j=0;j<rows;j++){
for(int k=0;k<columns;k++) {
for(int ii=0;ii<rows*columns*depth;ii++) {
d1 [ii] = S_p[ depth *rows *i + columns *k +j];
}
}
}
out put b[]= {1.1, 2.1, 3.2 , 4.1 ...}
But this does not work
rows * columns * depthcells. There's no need to iterate so deep, you already browse all the cells with your three firstforloops.