Java Array Normalize normalise(double[] a)

Here you can find the source of normalise(double[] a)

Description

normalise

License

Open Source License

Parameter

Parameter Description
a The array to normalise (the values in this array are altered).

Return

The given array with normalised values such that length(a) will return 1.

Declaration

public static double[] normalise(double[] a) 

Method Source Code

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

public class Main {
    /**//from www . jav a  2 s  .  c  o m
     * @param a The array to normalise (the values in this array are altered).
     * @return The given array with normalised values such that length(a) will return 1.
     */
    public static double[] normalise(double[] a) {
        double lengthInv = 1.0 / length(a);
        for (int i = 0; i < a.length; i++)
            a[i] *= lengthInv;
        return a;
    }

    /**
     * @param a The array to calculate the average for.
     * @return The average over all elements in the array.
     */
    public static double length(double[] a) {
        double c = 0;
        for (int i = 0; i < a.length; i++)
            c += a[i] * a[i];
        return Math.sqrt(c);
    }
}

Related

  1. normal0(double[] p1, double[] p2, double[] p3)
  2. normalCentralMoment(boolean[][] img, int p, int q)
  3. normalDist(double[] features, double[] avg, double[][] cov)
  4. normalForm(int[] a)
  5. normalHashCode(char[] val)
  6. normalise(double[] A)
  7. normalise(float[] array)
  8. normaliseActions(double[] actions)
  9. normaliseFloats(final float[] table, final int position, final int length)