Java Array Normalize normalize(double[] array)

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

Description

normalize

License

Open Source License

Declaration

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

Method Source Code

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

public class Main {
    public static float[] normalize(float[] values) {
        float sum = sum(values);
        for (int i = 0; i < values.length; i++) {
            values[i] = values[i] / sum;
        }//w  w  w. ja v a 2 s . c o m
        return values;
    }

    public static double[] normalize(double[] array) {
        double sum = sum(array);
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i] / sum;
        }
        return array;
    }

    public static double sum(double[] items) {
        double total = 0;
        for (double item : items) {
            total += item;
        }
        return total;
    }

    public static long sum(long[] items) {
        long total = 0;
        for (long item : items) {
            total += item;
        }
        return total;
    }

    public static float sum(float[] items) {
        float total = 0;
        for (float item : items) {
            total += item;
        }
        return total;
    }

    public static long sum(int[] items) {
        long total = 0;
        for (int item : items) {
            total += item;
        }
        return total;
    }
}

Related

  1. normalize(double[] a)
  2. normalize(double[] a)
  3. normalize(double[] ar)
  4. normalize(double[] array)
  5. normalize(double[] array)
  6. normalize(double[] bins)
  7. normalize(double[] d)
  8. normalize(double[] data)
  9. normalize(double[] data, double floor)