Java Array Normalize normalize(double[] data, double floor)

Here you can find the source of normalize(double[] data, double floor)

Description

normalize

License

Apache License

Declaration

public static void normalize(double[] data, double floor) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static boolean normalize(float[] data) {
        float sum = 0;
        for (float x : data)
            sum += x;//ww  w  .  j a  va  2  s.com
        if (sum == 0)
            return false;
        for (int i = 0; i < data.length; i++)
            data[i] /= sum;
        return true;
    }

    public static boolean normalize(double[] data) {
        double sum = 0;
        for (double x : data)
            sum += x;
        if (sum == 0)
            return false;
        for (int i = 0; i < data.length; i++)
            data[i] /= sum;
        return true;
    }

    public static boolean normalize(double[][] data) {
        double sum = 0;
        for (double[] v : data)
            for (double x : v)
                sum += x;
        if (sum == 0)
            return false;
        for (double[] v : data)
            for (int i = 0; i < v.length; i++)
                v[i] /= sum;
        return true;
    }

    public static boolean normalize(double[][][] data) {
        double sum = 0;
        for (double[][] m : data)
            for (double[] v : m)
                for (double x : v)
                    sum += x;
        if (sum == 0)
            return false;
        for (double[][] m : data)
            for (double[] v : m)
                for (int i = 0; i < v.length; i++)
                    v[i] /= sum;
        return true;
    }

    public static void normalize(double[] data, double floor) {
        double sum = 0;
        for (double x : data)
            sum += x;
        //      if (sum == 0) return;
        for (int i = 0; i < data.length; i++) {
            if (sum != 0)
                data[i] /= sum;

            if (data[i] < floor)
                data[i] = floor;
        }
    }
}

Related

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