Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

Compare matrix

Hi all
I have this matrix

double[][] arrayInput = {{1,0,1}};
double [][] arrayWeight = {{0.2,1.5,2.}};

arrayWeight = arrayInput
arrayWeight < arrayInput
arrayWeight > arrayInput


I am looking for a method that can help me compare both values
and return the result

public static double getEculideanDistance(double [][]arrayInput, double [][] arrayWeight)
{
retrun result;
}

Thanks in Advance
Avatar of for_yan
for_yan
Flag of United States of America image

I'm not sure there is one general definition in math - what
matrix is bigger than another, or what os the distance between matrices
if you want to compare them element by element and
calculate sum of squares of the distances that is how you do it:


public static double getEculideanDistance(double [][]arrayInput, double [][] arrayWeight) {

double output = 0.0;

    for (int row = 0; row < arrayInput.length; row++) {
            for (int col = 0; col < arrayInput[row].length; col++) {
                output += (arrayInput[row][col]-arrayWeight[row][col])*(arrayInput[row][col]-arrayWeight[row][col]);
            }
         
        }
     return Math.sqrt(output);
}
I'm not quite sure though that to the method it passes dimensions of two dimnsional array correctly,
you can then pass dimensions as integers

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
what does arrayWeight < arrayInput mean?
Avatar of ZURINET
ZURINET

ASKER

Hallo Van

Thanks a lot

regards
Avatar of ZURINET

ASKER

Perfect
You are always welcome