Java Array Normalize normalize(double[] bins)

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

Description

Scales bins to 0-1 scale.

License

Open Source License

Declaration

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

Method Source Code

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

public class Main {
    /**/*from ww w.j  a  v a 2 s  .  c o m*/
     * Scales bins to 0-1 scale. 
     *
     */
    public static double[] normalize(double[] bins) {
        double sum = 0;
        for (int i = 0; i < bins.length; i++) {
            sum += bins[i];
        }

        double[] normbins = new double[bins.length];
        for (int i = 0; i < bins.length; i++) {
            if (sum == 0)
                normbins[i] = 0;
            else
                normbins[i] = bins[i] / sum;
        }
        return (normbins);
    }
}

Related

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