Here you can find the source of normalizeArray(double[] array)
Parameter | Description |
---|---|
array | The array to be normalized |
public static double[] normalizeArray(double[] array)
//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; } }