Here you can find the source of normalise(double[] a)
Parameter | Description |
---|---|
a | The array to normalise (the values in this array are altered). |
public static double[] normalise(double[] a)
//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); } }