H
harryos
hi
i am trying to do a calculation like below.It iterates over the
elements of a double[][] using 2 for loops .Since i am using 2 for
loops to do this,i am worried that it will be slow for a large input
array.I thought of using a Matrix class like jama or colt to replace
the double[][] but am not sure how to reproduce the logic (finding the
sum value and filling the distances[].
if anybody can point out the correct way to handle this using a matrix
class pls help.
thanks in advance
harry
public double[] findDistances(double[][] temp){
double[] distances = new double[temp.length];
for (int i = 0; i < temp.length; i++) {
double sum = 0.0;
for (int j = 0; j < temp[0].length; j++) {
sum += temp[j];
}
distances = sum;
}
return distances;
}
i am trying to do a calculation like below.It iterates over the
elements of a double[][] using 2 for loops .Since i am using 2 for
loops to do this,i am worried that it will be slow for a large input
array.I thought of using a Matrix class like jama or colt to replace
the double[][] but am not sure how to reproduce the logic (finding the
sum value and filling the distances[].
if anybody can point out the correct way to handle this using a matrix
class pls help.
thanks in advance
harry
public double[] findDistances(double[][] temp){
double[] distances = new double[temp.length];
for (int i = 0; i < temp.length; i++) {
double sum = 0.0;
for (int j = 0; j < temp[0].length; j++) {
sum += temp[j];
}
distances = sum;
}
return distances;
}