Java Array Normalize normalize(float[] data)

Here you can find the source of normalize(float[] data)

Description

Normalize the given data.

License

Open Source License

Parameter

Parameter Description
data the data to normalize

Declaration

public static void normalize(float[] data) 

Method Source Code

//package com.java2s;
/*/*  w  w  w .j ava 2 s .c om*/
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electric Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

public class Main {
    /**
     * Normalize the given data.
     * 
     * @param data the data to normalize
     */
    public static void normalize(float[] data) {
        float sum = 0;
        for (float val : data) {
            sum += val;
        }
        if (sum != 0.0f) {
            for (int i = 0; i < data.length; i++) {
                data[i] = data[i] / sum;
            }
        }
    }
}

Related

  1. normalize(final double[] fir)
  2. normalize(final double[] tab)
  3. normalize(final double[] vec)
  4. normalize(final double[] vector, final double[] minima, final double[] maxima)
  5. normalize(float p[])
  6. normalize(float[] in)
  7. normalize(float[] in)
  8. normalize(float[] input)
  9. normalize(float[] v)