H
harryos
hi,
I have a 1D array of doubles each of which correspond to a row in a
matrix(a 2D array).The 1D array is unsorted.I need to sort the data in
the matrix based on the values of the 1D array.
ie,
double[] aVector = new double[]{0, 4.4521, 2.435, 3.654};
double[][] aMatrix = new double[][]{
{-0.142571, -0.692875, -0.064821, -0.567353},
{0.585747, -0.30768, -0.465215, 0.44606},
{-0.284163, -0.145485, 0.357779, 0.352733},
{-0.290938, -0.103984, 0.373695, 0.319145}
};
0 of aVector corresponds to the row {-0.142571, -0.692875, -0.064821,
-0.567353} of aMatrix.
3.654 of aVector corresponds to the row {-0.290938, -0.103984,
0.373695, 0.319145} etc..
After sorting the arrays should look like;
aVector = [4.4521, 3.654, 2.435, 0 ]
aMatrix = [
[0.585747, -0.30768, -0.465215, 0.44606 ],
[ -0.290938, -0.103984, 0.373695, 0.319145 ],
[-0.284163, -0.145485, 0.357779, 0.352733 ],
[-0.142571, -0.692875, -0.064821, -0.567353],
]
I thought of using a Hashtable<Double, double[]> and storing the
elements of aVector as keys, and rows of aMatrix as values.This would
let me sort the keys and finally build a sorted matrix from the
hashtable.But then this approach would fail if aVector contains a
duplicate element.
aVector = [4.4521, 3.654, 3.654, 0 ]
In this case, two rows of aMatrix correspond to the same value of
3.654 from aVector.It would make it impossible to use a Hashtable..Is
there any way I can get the sorting done in such a scenario?
Any help,advice would be appreciated..
thanks
harry
I have a 1D array of doubles each of which correspond to a row in a
matrix(a 2D array).The 1D array is unsorted.I need to sort the data in
the matrix based on the values of the 1D array.
ie,
double[] aVector = new double[]{0, 4.4521, 2.435, 3.654};
double[][] aMatrix = new double[][]{
{-0.142571, -0.692875, -0.064821, -0.567353},
{0.585747, -0.30768, -0.465215, 0.44606},
{-0.284163, -0.145485, 0.357779, 0.352733},
{-0.290938, -0.103984, 0.373695, 0.319145}
};
0 of aVector corresponds to the row {-0.142571, -0.692875, -0.064821,
-0.567353} of aMatrix.
3.654 of aVector corresponds to the row {-0.290938, -0.103984,
0.373695, 0.319145} etc..
After sorting the arrays should look like;
aVector = [4.4521, 3.654, 2.435, 0 ]
aMatrix = [
[0.585747, -0.30768, -0.465215, 0.44606 ],
[ -0.290938, -0.103984, 0.373695, 0.319145 ],
[-0.284163, -0.145485, 0.357779, 0.352733 ],
[-0.142571, -0.692875, -0.064821, -0.567353],
]
I thought of using a Hashtable<Double, double[]> and storing the
elements of aVector as keys, and rows of aMatrix as values.This would
let me sort the keys and finally build a sorted matrix from the
hashtable.But then this approach would fail if aVector contains a
duplicate element.
aVector = [4.4521, 3.654, 3.654, 0 ]
In this case, two rows of aMatrix correspond to the same value of
3.654 from aVector.It would make it impossible to use a Hashtable..Is
there any way I can get the sorting done in such a scenario?
Any help,advice would be appreciated..
thanks
harry