Java Array Normalize normalise(float[] array)

Here you can find the source of normalise(float[] array)

Description

Normalise length of array to 1.0.

License

Open Source License

Parameter

Parameter Description
array the array

Declaration

public static void normalise(float[] array) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  ww w .ja va 2s.  co  m
     * Normalise length of array to 1.0. Writes over array
     * 
     * @param array the array
     */
    public static void normalise(float[] array) {
        float sumsq = 0.0f;
        for (int i = 0; i < array.length; i++)
            sumsq += array[i] * array[i];

        float weight = 1.0f / (float) Math.sqrt(sumsq);
        for (int i = 0; i < array.length; i++)
            array[i] *= weight;
    }

    /**
     * Normalise length of array to 1.0. Writes over array
     * 
     * @param array the array
     */
    public static void normalise(double[] array) {
        double sumsq = 0.0f;
        for (int i = 0; i < array.length; i++)
            sumsq += array[i] * array[i];

        double weight = 1.0f / Math.sqrt(sumsq);
        for (int i = 0; i < array.length; i++)
            array[i] *= weight;
    }
}

Related

  1. normalDist(double[] features, double[] avg, double[][] cov)
  2. normalForm(int[] a)
  3. normalHashCode(char[] val)
  4. normalise(double[] a)
  5. normalise(double[] A)
  6. normaliseActions(double[] actions)
  7. normaliseFloats(final float[] table, final int position, final int length)
  8. normaliseHeaders(String[] headers)
  9. normaliseSum(double[] a)