Java Euclidean Distance euclidean(Double[] a, Double[] b)

Here you can find the source of euclidean(Double[] a, Double[] b)

Description

Compute the Euclidean distance between two arrays of the same size.

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Return

the Euclidean distance

Declaration

public static double euclidean(Double[] a, Double[] b) 

Method Source Code

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

public class Main {
    /**// ww  w  . j  a v  a2 s.  co  m
     * Compute the Euclidean distance between two arrays of the same size.
     * @param a
     * @param b
     * @return the Euclidean distance
     */
    public static double euclidean(Double[] a, Double[] b) {
        double sum = 0.0;

        for (int i = 0; i < a.length; i++) {
            double diff = a[i] - b[i];
            sum += diff * diff;
        }

        return Math.sqrt(sum);
    }
}

Related

  1. euclidean(double[] _a, double[] _b)
  2. euclidean(double[] a, double[] b)
  3. euclidean(double[] features1, double[] features2)
  4. euclidean(double[] x1, double[] x2)
  5. euclidean(double[] xvalues, double[] yvalues, int[] include)