J
jimgardener
hi
i wrote the following code to normalise an double[][]..but it takes
too much time when i try arrays with about 10,000 number of columns (i
need this for an image processing app).can someone tell me how this
code can be improved?
thanks
Jim
public void normaliseArray(double[][] temp){
double[] mvals=new double[temp.length];
for(int i=0;i<temp.length;i++){
mvals=max(temp);
}
for(int i=0;i<temp.length;i++){
for(int j=0;j<temp[0].length;j++){
temp[j]/=mvals;
}
}
}
public static void main(String[] args){
double[][] myarray=new double[][]{
{1.,3.,5.,6.,8.},
{6.,8.,9.,2.,4.},
{4.,10.,2.,1.,5.},
{7.,1.,8.,2.,9.}
};
new MyClass().normaliseArray(myarray);
/* result should be
0.1250 0.3750 0.6250 0.7500 1.0000
0.6667 0.8889 1.0000 0.2222 0.4444
0.4000 1.0000 0.2000 0.1000 0.5000
0.7778 0.1111 0.8889 0.2222 1.0000
*/
}
i wrote the following code to normalise an double[][]..but it takes
too much time when i try arrays with about 10,000 number of columns (i
need this for an image processing app).can someone tell me how this
code can be improved?
thanks
Jim
public void normaliseArray(double[][] temp){
double[] mvals=new double[temp.length];
for(int i=0;i<temp.length;i++){
mvals=max(temp);
}
for(int i=0;i<temp.length;i++){
for(int j=0;j<temp[0].length;j++){
temp[j]/=mvals;
}
}
}
public static void main(String[] args){
double[][] myarray=new double[][]{
{1.,3.,5.,6.,8.},
{6.,8.,9.,2.,4.},
{4.,10.,2.,1.,5.},
{7.,1.,8.,2.,9.}
};
new MyClass().normaliseArray(myarray);
/* result should be
0.1250 0.3750 0.6250 0.7500 1.0000
0.6667 0.8889 1.0000 0.2222 0.4444
0.4000 1.0000 0.2000 0.1000 0.5000
0.7778 0.1111 0.8889 0.2222 1.0000
*/
}