Java Array Normalize normalize(double[] xs)

Here you can find the source of normalize(double[] xs)

Description

normalize

License

Open Source License

Declaration

public static double[] normalize(double[] xs) 

Method Source Code

//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;
    }
}

Related

  1. normalize(double[] vector)
  2. normalize(double[] w)
  3. normalize(double[] weights)
  4. normalize(double[] weights)
  5. normalize(double[] x)
  6. normalize(double[][] matrix, double lower, double upper)
  7. normalize(double[][] result)
  8. normalize(double[][] X)
  9. normalize(final byte[] input, final int bit)