Java Array Normalize normalizeArray(double[] array)

Here you can find the source of normalizeArray(double[] array)

Description

normalize Array

License

Open Source License

Parameter

Parameter Description
array The array to be normalized

Return

An array with the normalized values of the given array

Declaration

public static double[] normalizeArray(double[] array) 

Method Source Code

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

public class Main {
    /**//from  w w  w . ja va 2s  .  c  o  m
     * @brief Normalizes the values of a given array
     *        The values of the given array are mapped to [0, 100]. Each value is divided by the sum
     *        of the initial values and multiplied by 100. The initial values should be greater than
     *        zero.
     *
     * @param array
     *     The array to be normalized
     *
     * @return An array with the normalized values of the given array
     */
    public static double[] normalizeArray(double[] array) {
        int length = array.length;

        double sum = 0;
        for (double item : array) {
            sum += item;
        }

        double[] normalizedArray = new double[length];
        for (int i = 0; i < length; i++) {
            normalizedArray[i] = array[i] / sum * 100;
        }

        return normalizedArray;
    }
}

Related

  1. normalize(String[] slist)
  2. normalize01(float[] array)
  3. normalize2(double[] x)
  4. normalize3(float[] result, float[] a)
  5. normalizeAndInvertValues(double[] values, double maxValue, double minValue)
  6. normalizeArray(double[] hist)
  7. normalizeArray(String[] raw, int expectedSize)
  8. normalizeArrays(int normalizeToLength, String[]... arraysToNormalize)
  9. normalizeCharacterData(char[] ch, int start, int length)