If the idea is to reorganize the data
based on the index store in ID_list
. Iterate this array.
double[][] new_data = new double[ID_list.length][];
for(int i = 0; i < ID_list.length; ++i){
new_data[i] = data[ID_list[i]];
}
This would only duplicate the reference of the array, not the value itself so this won't double the memory usage.
Note : I used ID_list length to initialise the array, this will be better if you only need some column.
Edit :
Here is an example to show that a 2D arrays is simply a arrays of arrays.
int[][] original = {
{1,2,3},
{4,5,6}
};
int[][] copy = new int[1][];
copy[0] = original[0];
System.out.println(original[0]);
System.out.println(copy[0]);
System.out.println(Arrays.toString(original[0]));
System.out.println(Arrays.toString(copy[0]));
original[0][1] = 7;
System.out.println(Arrays.toString(original[0]));
System.out.println(Arrays.toString(copy[0]));
Will output
[I@3941a79c //change on each run
[I@3941a79c
[1, 2, 3] //original[0]
[1, 2, 3] //copy[0]
[1, 7, 3] //original[0] after the update
[1, 7, 3] //copy[0]
Here is the JSL about Arrays member. This can be interesting to read.