Java Array Normalize normalizeHistogram(int[] h)

Here you can find the source of normalizeHistogram(int[] h)

Description

normalize Histogram

License

Open Source License

Declaration

public static double[] normalizeHistogram(int[] h) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    public static double[] normalizeHistogram(double[] h) {
        // find max histogram entry
        double max = h[0];
        for (int i = 0; i < h.length; i++) {
            if (h[i] > max)
                max = h[i];//  w  w  w . j a  v  a 2  s. c o m
        }
        if (max == 0)
            return null;
        // normalize
        double[] hn = new double[h.length];
        double s = 1.0 / max;
        for (int i = 0; i < h.length; i++) {
            hn[i] = s * h[i];
        }
        return hn;
    }

    public static double[] normalizeHistogram(int[] h) {
        // find the max histogram entry
        int max = h[0];
        for (int i = 0; i < h.length; i++) {
            if (h[i] > max)
                max = h[i];
        }
        if (max == 0)
            return null;
        // normalize
        double[] hn = new double[h.length];
        double s = 1.0 / max;
        for (int i = 0; i < h.length; i++) {
            hn[i] = s * h[i];
        }
        return hn;
    }
}

Related

  1. normalizeFromLog10(double[] array, boolean takeLog10OfOutput)
  2. normalizeFromLog10(final double[] array, final boolean takeLog10OfOutput, final boolean keepInLogSpace)
  3. normalizeFromRealSpace(final double[] array)
  4. normalizeHeightMap(float heightMap[])
  5. normalizeHeightMapCopy(float heightMap[])
  6. normalizeHistogram(int[] hist)
  7. normalizeHistogramToBase(int[] hist, double base)
  8. normalizeInnerPointDistanceMax(double[][] distances, double maxDist)
  9. normalizeL2(double[] a)