Here you can find the source of euclideanDistance(double[] vector1, double[] vector2)
Parameter | Description |
---|---|
vector1 | a parameter |
vector2 | a parameter |
public static double euclideanDistance(double[] vector1, double[] vector2)
//package com.java2s; //License from project: LGPL public class Main { /**/*from w w w. j a v a2 s . co m*/ * Returns Euclidean distance between the two vectors * * @param vector1 * @param vector2 * @return */ public static double euclideanDistance(double[] vector1, double[] vector2) { double sum = 0; for (int i = 0; i < vector1.length; i++) { sum += (vector1[i] - vector2[i]) * (vector1[i] - vector2[i]); } return Math.sqrt(sum); } /** * Returns Euclidean distance between the two vectors ignoring null elements of vector1. * * @param vector1 * @param vector2 * @return */ public static double euclideanDistance(Double[] vector1, double[] vector2) { double sum = 0; for (int i = 0; i < vector1.length; i++) { if (vector1[i] != null) sum += (vector1[i] - vector2[i]) * (vector1[i] - vector2[i]); } return Math.sqrt(sum); } }