I'm trying to find a programable way to regenerate any size 3D array - consists of 1 and 0 only - by knowing the three 2d arrays that show the sum of the original array on each axis as the pictures show :
example of the sum code :
int D = 3 ;
int xsum[D][D] = {0};
int ysum[D][D] = {0};
int zsum[D][D] = {0};
for(int x = 0 ; x<D ;x++){
for(int y = 0 ; y<D ;y++){
for(int d = 0 ;d<D;d++){
zsum[x][y] = zsum[x][y] + array[d][y][x];
}
}
}
for(int x = 0 ; x<D ;x++){
for(int z = 0 ;z<D ;z++){
for(int d = 0 ;d<D;d++){
ysum[x][z] = ysum[x][z]+array[z][d][x];
}
}
}
for(int z = 0 ;z<D ;z++){
for(int y = 0 ; y<D ;y++){
for(int d = 0 ;d<D;d++){
xsum[z][y] = xsum[z][y]+ array[z][y][d];
}
}
}
I tried the easiest algorithm I could think of something like :
for(int x = 0 ; x<D ; x++) {
for(int y = 0 ; y<D ; y++) {
if(zsum[x][y]> 0 ){
for(int z = 0 ; z<D ;z++){
if(xsum[z][y] > 0 && ysum[x][z] > 0){
rearray[z][y][x]= 1;
zsum[x][y]-- ;
xsum[z][y]-- ;
ysum[x][z]-- ;
}
}
}
}
}
it produces somthing very similar to the original array the bold numbers are different:
1,1,0
0,1,0
0,0,0
1 ,1, 0
1,1,1
0 ,1, 1
1,0,1 0,0,1
0,0,1
however when I make D = 4 or 5 more errors occur can anyone explain or suggest a correct algorithm to solve this problem ?
While there may happend to be solutions for particular values with sizes>3, there is no guaranteed solution because information is being lost in the summing - as it happens for size 3, there are 27 elements in the 3-D array, and also 27 elements in the projection, so it may be possible for there to always be a solution. However for larger sizes, for example 5, there are 125 elements in the 3-D array and only 75 in the projected 2-D arrays.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.