Java Array Normalize normalize(float[] input)

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

Description

Normalizes the given input in place to make it unit length.

License

Open Source License

Declaration

public static void normalize(float[] input) 

Method Source Code

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

public class Main {
    /**/*ww w .j a v  a  2 s. c om*/
     * Normalizes the given input in place to make it unit length.
     */
    public static void normalize(float[] input) {
        double normSq = 0;
        for (int i = 0; i < input.length; ++i) {
            normSq += input[i] * input[i];
        }
        float norm = (float) Math.sqrt(normSq);
        for (int i = 0; i < input.length; ++i) {
            input[i] = input[i] / norm;
        }
    }
}

Related

  1. normalize(final double[] vector, final double[] minima, final double[] maxima)
  2. normalize(float p[])
  3. normalize(float[] data)
  4. normalize(float[] in)
  5. normalize(float[] in)
  6. normalize(float[] v)
  7. normalize(float[] vec)
  8. normalize(float[][] vals, float min, float max)
  9. normalize(int[] a)