Java Array Normalize normalize(double[] doubleArray)

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

Description

normalize

License

Open Source License

Declaration

static double[] normalize(double[] doubleArray) 

Method Source Code


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

import java.util.Arrays;

public class Main {
    static double[] normalize(double[] doubleArray) {
        // Normalize a double array
        double arraySum = sum(doubleArray);
        double[] arrayNormalized = new double[doubleArray.length];
        for (int i = 0; i < doubleArray.length; i++) {
            arrayNormalized[i] = doubleArray[i] / arraySum;
        }/*w w  w  .  j a va 2 s  .  c  o m*/
        return arrayNormalized;
    }

    public static double sum(int[] intArray) {
        double[] doubleArray = Arrays.stream(intArray).asDoubleStream().toArray();
        return sum(doubleArray);
    }

    public static double sum(double[] doubleArray) {
        // Sum the elements in a double array
        double arraySum = 0;
        for (double d : doubleArray) {
            arraySum += d;
        }
        return arraySum;
    }
}

Related

  1. normalize(double[] bins)
  2. normalize(double[] d)
  3. normalize(double[] data)
  4. normalize(double[] data, double floor)
  5. normalize(double[] descriptor)
  6. normalize(double[] doubles)
  7. normalize(double[] doubles)
  8. normalize(double[] doubles)
  9. normalize(double[] doubles, double sum)