I have the Following 2d matrix :
int [][] states = new int [][] {{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1},{2,2}};
I want getting a 3d matrix with this output :
[0,1] | [0,2] | [1,0] | [1,1] | [1,2] | [2,0] | [2,1] | [2,2]
[0,0] | [0,2] | [1,0] | [1,1] | [1,2] | [2,0] | [2,1] | [2,2]
[0,0] | [0,1] | [1,0] | [1,1] | [1,2] | [2,0] | [2,1] | [2,2]
[0,0] | [0,1] | [0,2] | [1,1] | [1,2] | [2,0] | [2,1] | [2,2]
[0,0] | [0,1] | [0,2] | [1,0] | [1,2] | [2,0] | [2,1] | [2,2]
[0,0] | [0,1] | [0,2] | [1,0] | [1,1] | [2,0] | [2,1] | [2,2]
[0,0] | [0,1] | [0,2] | [1,0] | [1,1] | [1,2] | [2,1] | [2,2]
[0,0] | [0,1] | [0,2] | [1,0] | [1,1] | [1,2] | [2,0] | [2,2]
[0,0] | [0,1] | [0,2] | [1,0] | [1,1] | [1,2] | [2,0] | [2,1]
I tried the following code :
int [][] states = new int [][] {{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1},{2,2}};
int [][][] actions = new int[states.length][states.length][2];
// Remplissage :
for (int i = 0; i < states.length; i++) {
int k = 0;
for(int j =0 ;j<states.length;j++) {
for(int c = 0;c<states[i].length;c++) {
actions[i][j] = states[j];
System.out.print(actions[i][j][c]+"");
}
}
System.out.println();
}
but I didn't get the desired result.
question from:
https://stackoverflow.com/questions/65882075/creating-a-3d-matrix-from-2d-matrix