Java Array Normalize normalize(double[] weights)

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

Description

Returns an array of doubles resulting from the normalization of a given array of (positive) doubles.

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww.  ja  v a 2  s .co m
     * Returns an array of doubles resulting from the normalization of a given
     * array of (positive) doubles.
     */
    public static double[] normalize(double[] weights) {
        double[] result = new double[weights.length];
        double sum = sum(weights);
        for (int i = 0; i != weights.length; i++)
            result[i] = weights[i] / sum;
        return result;
    }

    /** Returns the sum of an array of doubles. */
    public static double sum(double[] array) {
        double result = 0;
        for (int i = 0; i != array.length; i++)
            result += array[i];
        return result;
    }
}

Related

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