Java Euclidean Distance euclidean(double[] x1, double[] x2)

Here you can find the source of euclidean(double[] x1, double[] x2)

Description

euclidean

License

Open Source License

Declaration

public static double euclidean(double[] x1, double[] x2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double euclidean(double[] x1, double[] x2) {
        double[] x3 = arraySubtract(x1, x2);
        double result = 0;
        for (double x : x3)
            if (x != 0)
                result += x * x;/* w  w w  .j  a  va  2s . c o  m*/
        return Math.pow(result, 0.5);
    }

    public static double[] arraySubtract(double[] x1, double[] x2) {

        double[] result = new double[x1.length];
        for (int i = 0; i < x1.length; i++) {
            result[i] = x1[i] - x2[i];
        }
        return result;
    }
}

Related

  1. euclidean(double[] _a, double[] _b)
  2. euclidean(double[] a, double[] b)
  3. euclidean(Double[] a, Double[] b)
  4. euclidean(double[] features1, double[] features2)
  5. euclidean(double[] xvalues, double[] yvalues, int[] include)
  6. euclidean_distance(double[] vec1, double[] vec2)
  7. euclideanDist(double[] ePointOne, double[] ePoint2)
  8. euclideanDist(final double[] vec1, final double[] vec2, int n)