Java Array Normalize normalize(double[] x)

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

Description

normalize

License

Open Source License

Declaration

public static double normalize(double[] x) 

Method Source Code

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

public class Main {
    public static double normalize(double[] x) {
        double len = 0;
        for (int i = 0; i < x.length; i++)
            len += x[i] * x[i];/*from ww  w  . j a  va2s .  c  om*/

        len = Math.sqrt(len);

        if (len <= 0.0)
            return 0.0;
        scale(x, 1.0 / len);

        return len;
    }

    public static void scale(double[] x, double s) {
        for (int i = 0; i < x.length; i++)
            x[i] *= s;
    }

    public static void scale(double[][] m, double s) {
        for (int i = 0; i < m.length; i++)
            scale(m[i], s);
    }
}

Related

  1. normalize(double[] vector)
  2. normalize(double[] vector)
  3. normalize(double[] w)
  4. normalize(double[] weights)
  5. normalize(double[] weights)
  6. normalize(double[] xs)
  7. normalize(double[][] matrix, double lower, double upper)
  8. normalize(double[][] result)
  9. normalize(double[][] X)