Here you can find the source of normalize(double[] xs)
public static double[] normalize(double[] xs)
//package com.java2s; //License from project: Open Source License public class Main { public static double[] normalize(double[] xs) { double l2norm = Math.sqrt(dotProduct(xs, xs)); return scalarProduct(1.0 / l2norm, xs); }//from w ww .j av a 2s . c o m public static double dotProduct(double[] xs1, double[] xs2) { double product = 0; for (int i = 0; i < xs1.length; i++) { product += xs1[i] * xs2[i]; } return product; } public static double[] scalarProduct(double x, double[] xs) { double[] product = new double[xs.length]; for (int i = 0; i < product.length; i++) { product[i] = x * xs[i]; } return product; } }