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
ZURINETAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:


I checked (modified your input for simplicity and this
code worked for me
public class AnyName {
  static  double[][] arrayInput = {{4,0,5}};
    static  double [][] arrayWeight = {{1,0,1}};

     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);
     }
  public static void main(String[] args) {


          System.out.println("result: " + getEculideanDistance(arrayInput, arrayWeight));
 }
}

Open in new window



result: 5.0

Open in new window

0
 
for_yanCommented:
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

0
 
ozoCommented:
what does arrayWeight < arrayInput mean?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
ZURINETAuthor Commented:
Hallo Van

Thanks a lot

regards
0
 
ZURINETAuthor Commented:
Perfect
0
 
for_yanCommented:
You are always welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.